Reputation: 5055
After adding a binding for F4 to a JTable
inside a panel, the standard behavior for TAB stops working. Instead of the expected jump to the next cell, the current cell goes into edit mode.
This happens when using ActionMap
/InputMap
or adding a KeyListener
to the table
ActionMap map = new ActionMap();
map.put("f4Action", new F4Action());
map.setParent(this.getActionMap());
InputMap input = new InputMap();
input.put(KeyStroke.getKeyStroke("F4"), "f4Action");
input.setParent(this.getInputMap());
// this is the table in question
table.setInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, input);
table.setActionMap(map);
or just table.addKeyListener(new KeyListener() { /*...*/ }
with the other approach.
Is it possible to keep the standard behavior and only override explicit keybindings? And how can this be done.
Upvotes: 0
Views: 120
Reputation: 324108
ActionMap map = new ActionMap();
Don't create a new ActionMap
.
Just use the existing ActionMap
:
ActionMap map = table.getActionMap();
See Key Bindings for a list of all the current bindings and templates of how to customize the bindings.
Upvotes: 3