tags:

views:

74

answers:

2

So I'm a bit nonplussed at the JSlider default key bindings for vertical sliders.

  • Home: goes to the bottom (why not the top?)
  • End: goes to the top (why not the bottom?)
  • PageUp/PageDown: direction good, but goes up by some amount K which I can't control
  • up/down arrow keys: direction good, but goes up by 1, and I have a high-granularity slider (0 to 65535) which I would like to have a little more intuitive control over.

Is there a way to customize this behavior?

A: 

There isn't a straightforward way as for menus. But you can probably use actions for your purpose: http://java.sun.com/docs/books/tutorial/uiswing/misc/action.html

Davide
+2  A: 

You can access the keybindings via the getInputMap and getActionMap methods. For example, to switch the home/end key bindings (make Home go to the top, and end go to the bottom):

InputMap im = yourSlider.getInputMap();
im.put(KeyStroke.getKeyStroke("HOME"), "maxScroll");
im.put(KeyStroke.getKeyStroke("END"), "minScroll");

Here's a tutorial on key bindings.

JRL
Correct and complete answer
Thorsten S.
Great! thanks a bunch.
Jason S