Java Swing FAQ: How do I increase the JScrollPane scrolling speed when using the mouse wheel?
Once you put a component (JTextArea, JEditorPane, JTable) into a JScrollPane in a Java Swing application, you’ll quickly see that the default scrolling speed when trying to vertically scroll the viewport with the mousewheel is very slow. To make your scroll pane faster, i.e., more like a native Mac or Windows application, you’ll want to increase this default mousewheel vertical scrolling speed.
I’ve seen a lot of different attempts at doing this, but in the end it turns out that the solution is simple, just one line of Java source code. Just use the reference to your JScrollPane object, get the vertical scroll bar from it using
getVerticalScrollBar, and then call
setUnitIncrement on it, like this:
Believe it or not, that one line of code will solve the JScrollPane mousewheel vertical scrolling problem.
Note: The number
16 is just a number I chose because it seems to make the mousewheel scroll speed similar to other applications, but you can adjust this number to get the scrolling speed you want for your application.
2019 Update: These days I find that I need to slow down the JScrollPane scrolling speed, but the same solution still works.