Reputation: 11
Hey you all, just a quick question of what i havent found anywhere. Im adding a scrollpane to a JPanel, with 2 JScrollBars. One vertical and one horizontal. Everything works fine just that i dont want the ScrollBars to scroll using the arrow keys. How do i achieve this?
I´ve been checking out adjustmentlisteners but really havent found anything of high value to me. Thanks for any help!
Upvotes: 1
Views: 672
Reputation: 51524
you have to tweak the keybinding in the scrollPane's inputMap and point the navigation keys into nirwana, like:
InputMap inputMap = scrollPane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
inputMap.put(KeyStroke.getKeyStroke("RIGHT"), "do-nothing");
// same for all navigation keys you want to disable
...
to find which keyStrokes are registered, look into the BasicLookFeel - the section in getDefaults which relates to "ScrollPane"
Beware: that's highly unusual, you user's might be annoyed!
Upvotes: 1