I have a swing application which contains several panels. I want one of
the panels to respond to the arrow keys and have registered accelerators
in a JMenu which do this correctly.
However, one of the other panels contains a JTree, and when this is
selected with the mouse it grabs the arrow key events first and they
don't make it back to the menu.
I've tried removing the binding in the tree by doing
tree.getInputMap().put(arrowKeyStroke,"none")
..for each arrow key. This stops the tree from responding to the key,
but it doesn't allow the event to pass back to the menu.
I've also tried using:
tree.unregisterKeyboardAction(arrowKeyStroke)
and
tree.getInputMap.remove(arrowKeyStroke)
..which didn't seem to have any effect at all.
How can I stop the JTree from capturing these events at all?
Cheers
Simon.
Simon Andrews - 22 Jun 2007 16:03 GMT
> I have a swing application which contains several panels. I want one of
> the panels to respond to the arrow keys and have registered accelerators
[quoted text clipped - 3 lines]
> selected with the mouse it grabs the arrow key events first and they
> don't make it back to the menu.
Replying to myself in case anyone else can benefit from this.
I've got around this in the end by making a subclass of JTree which
immediately gives away keyboard focus as soon as it gets it.
private class UnfocusableTree extends JTree implements FocusListener {
public UnfocusableTree (TreeModel m) {
super(m);
addFocusListener(this);
}
public void focusGained(FocusEvent e) {
application.requestFocus();
}
public void focusLost(FocusEvent e) {}
}