Alan Alan - 1 year ago 160
Java Question

How to disable arrow keys for JSliders?

I want to use my arrows keys to move something on the screen but after I click on a

to use it and I use the arrows keys, they are moving the slider instead of the object. I can’t find any method to disable this. (After clicking on a slider, the sliding arrow changes from a black outline to a blue one {my presumption indicating that the arrows keys are “locked” onto the slider.})

Answer Source

Try slider.setFocusable(false);

But for a complex application, ensuring you always have control over what the arrows do may require the KeyboardFocusManager and KeyEventDispatcher APIs. These let you divert arrow (or any) keystrokes from normal handling, so must be used carefully.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download