A JPanel has a JScrollPane that contains yet another JPanel or two. My life depends on increasing the scroll speed using a keyboard’s directional arrows. After careful deliberation, the powers that be decided that: sc.getVerticalScrollBar().setUnitIncrement(240); should only be applicable to a mouse, in a clever ruse to elicit minor annoyances amongst java developers. Is there anything that can be done to increase scroll speed? My life hangs in the balance.
A JPanel has a JScrollPane that contains yet another JPanel or two. My life
Share
You have to use a combination of InputMap.put and ActionMap.put to capture the keyboard events for the components contained on your
JScrollPaneand process the keyboard events when theJScrollPanehas the focus. Since the default increment value for scrolling is 1 you should add or substract the desired increment value to the current value of the scrollbar forJScrollPanewhich you can get withJScrollPane.getVerticalScrollBar().getValue()and set withJScrollPane.getVerticalScrollBar().setValue(int).An example of capturing events for the contained elements withing JScrollPane can be done with this code, I’ve done with buttons, but you get the point (Sorry for the bad organization of the code):
We register to listen and process that event with:
The key code that perform the value of
JScrollBarincrement is of the AbstractAction (in this case when the user press the up key).What you should do is to complete the events when your JScrollPane has the focus, but that should be trivial.
Hope it helps to save your life 😛 or at least serve you as a starting point.