KeyStroke[] keys = new KeyStroke[]{
KeyStroke.getKeyStroke("F2"),
KeyStroke.getKeyStroke("ENTER"),
KeyStroke.getKeyStroke("ESCAPE")});
InputMap im = new FilteringInputMap(dbTable.getTable().getInputMap(WHEN_FOCUSED), keys);
dbTable.getTable().setInputMap(WHEN_FOCUSED, im);
im = new FilteringInputMap(dbTable.getTable().getInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT), keys);
dbTable.getTable().setInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, im);
And here is the new InputMap class:
import javax.swing.InputMap;
import javax.swing.KeyStroke;
/**
* An input map used by components that extend swing components that bind
* keystrokes to unwanted actions (Such as ESCAPE, ENTER or F2 in a JTable that
* does not do any editing). For the named keystrokes it return null for the
* binding and so Swing will look outside this component for a binding.
*
* @author Reg Whitton
*/
public class FilteringInputMap extends InputMap {
private KeyStroke[] keys;
public FilteringInputMap(InputMap parent, KeyStroke[] keys) {
super();
setParent(parent);
this.keys = keys;
}
public Object get(KeyStroke keyStroke) {
for(int i=0; i<keys.length; i++){
if(keyStroke.equals(keys[i])){
return null;
}
}
return super.get(keyStroke);
}
}