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.

