views:

59

answers:

1

I'm trying to redefine the behavior of the Tab key in a JRadioButton so it behaves like radio buttons in other GUI applications, that is:

  • Arrow keys cycle through the radio buttons in the ButtonGroup (I have this working)
  • Tab moves focus to the next component after the last radio button in the group (Problem area)

I have an Action that performs the necessary steps to find the right component to focus and everything, but adding an entry to the InputMap doesn't seem to work:

getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0), "jumpNext");
getActionMap().put("jumpNext", new JumpNextAction());

My entry in the input map for Tab seems to be ignored, as the action never gets executed. I imagine that this is probably because the KeyboardFocusManager or something related is consuming the Tab event before it gets to the component's input map.

Any ideas on how I can stop this behavior and have my custom Tab behavior instead?

+1  A: 

It may not be getting to the inputmap as you said because of the KeyboardFocusManager, however if you put a lower level keyListener on it I bet you can intercept and consume() the event so the KeyboardFocusManager doesn't handle it.

Alternatively, you may be able to call the JComponent.setFocusTraversalKeys() method on the radio buttons, removing the default tab key and then then inputmap might handle it like you were trying.

Nemi
setFocusTraversalKeys() with an empty set did the trick! Thanks a bunch.
Joe Attardi