开发者

JSlider key bindings

开发者 https://www.devze.com 2022-12-15 06:13 出处:网络
So I\'m a bit nonplussed at the JSlider default key bindings for vertical sliders. Home: goes to the bottom (why not the top?)

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开发者_如何学Python: 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?


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消