开发者

JScrollBar, remove keyListener?

开发者 https://www.devze.com 2023-03-02 08:21 出处:网络
H开发者_开发问答ey 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 t

H开发者_开发问答ey 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!


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!

0

精彩评论

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