Question

I want to use my arrows keys to move something on the screen but after I click on a JSlider 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.})

Was it helpful?

Solution

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.

OTHER TIPS

Key bindings should provide a solution to this problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top