Java 扩展JTable中的键绑定
将F4绑定添加到面板内的Java 扩展JTable中的键绑定,java,swing,awt,keylistener,key-bindings,Java,Swing,Awt,Keylistener,Key Bindings,将F4绑定添加到面板内的JTable后,选项卡的标准行为将停止工作。当前单元格将进入编辑模式,而不是预期的跳转到下一个单元格 使用ActionMap/InputMap或向表中添加KeyListener时会发生这种情况 ActionMap map = new ActionMap(); map.put("f4Action", new F4Action()); map.setParent(this.getActionMap()); InputMap input = new InputMap(); i
JTable
后,选项卡的标准行为将停止工作。当前单元格将进入编辑模式,而不是预期的跳转到下一个单元格
使用ActionMap
/InputMap
或向表中添加KeyListener
时会发生这种情况
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);
或者只使用另一种方法table.addKeyListener(newKeyListener(){/*…*/}
是否有可能保持标准行为而只覆盖显式键绑定?如何做到这一点
ActionMap map = new ActionMap();
不要创建新的ActionMap
只需使用现有的ActionMap
:
ActionMap map = table.getActionMap();
有关当前所有绑定的列表以及如何自定义绑定的模板,请参阅
不要创建新的ActionMap
只需使用现有的ActionMap
:
ActionMap map = table.getActionMap();
有关如何自定义绑定的所有当前绑定和模板的列表,请参阅。认为重写特定键的解决方案在于
InputMap
s的层次结构。但是您的解决方案更简单、直接……当然,工作起来^^^认为重写特定键的解决方案在于