Skip to content
Advertisement

Java Swing JScrollPane not scrolling when shift held down and using mouse wheel

I have a simple Java Swing program defined below:

JavaScript

The program consists of a simple JScrollPane with multiple buttons inside of it. Only vertical scrolling is enabled. It works fine.

However, the problem is, when I am holding down the ‘shift’ key, vertical scrolling does not work when I am using the mouse wheel to scroll. Vertical scrolling only works when I drag the scrollbar or let go of the ‘shift’ key.

Usually, in a JScrollPane, when the ‘shift’ key is held down, and the mouse wheel is used, it scrolls horizontally instead of vertically. However, I have disabled horizontal scrolling.

How would I go about enabling vertical scrolling using the mouse wheel if the user is holding down ‘shift’?

Advertisement

Answer

I don’t think there is a simple way to do this because normally you would only need the shift scroll when scrolling in more than one direction.

You could try adding a key listener to your JFrame and setting the wheel on your mouse to scroll vertically whenever the shift key is pressed. I tried it with this code and it worked just fine:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement