JTextPane: scroll with wheel when using addMouseWheelListener()

Hello! I have JTextPane with code (code editor) with busy mouseWheelListener() which is used to increase/decrease font size when Ctrl key is hold. I think I overwrite default wheelListener behavior, so it is impossible to scroll text with a wheel. How can I do that?

My code is below:

JTextPane editor =new JTextPane();

editor.addMouseWheelListener(new MouseWheelListener(){

publicvoid mouseWheelMoved(MouseWheelEvent e){

if (e.getModifiers() == InputEvent.CTRL_MASK){

int notches = e.getWheelRotation();

Component originator = e.getComponent();

float prevFontSize = originator.getFont().getSize();

if (notches < 0){//if UP then descrease font size

if (prevFontSize > 12.0f)

originator.setFont(originator.getFont().deriveFont(prevFontSize - 2));

}

else{//if DOWN increase

originator.setFont(originator.getFont().deriveFont(prevFontSize + 2));

}

}

}

});

JScrollPane editorWithScrolls =new JScrollPane(editor);

//...nothing happens when I scroll mouse wheel...

How can I scroll text with mouse wheel in my case?

P.S. May be anybody knows how to scroll and set caret to given line(word)?

Thank you.

[1980 byte] By [J-inspirea] at [2007-10-3 2:44:13]
# 1
Does anybody have any ideas?I feel that the decision is nearby.
J-inspirea at 2007-7-14 20:32:39 > top of Java-index,Desktop,Core GUI APIs...
# 2

the textpane processes the event before it gets to the scrollpane.

you need to "pass it on"

else { //if DOWN increase

p.setFont(originator.getFont().deriveFont(prevFontSize + 2));

}

}

[scrollpane].dispatchEvent(e);//<--

}

});

Michael_Dunna at 2007-7-14 20:32:39 > top of Java-index,Desktop,Core GUI APIs...
# 3
Thank you. You're really helped me. I knew that it was somewhere on the surface. :))
J-inspirea at 2007-7-14 20:32:39 > top of Java-index,Desktop,Core GUI APIs...