【发布时间】:2017-05-05 22:33:18
【问题描述】:
将 F4 的绑定添加到面板内的 JTable 后,TAB 的标准行为停止工作。当前单元格进入编辑模式,而不是预期的跳转到下一个单元格。
当使用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(new KeyListener() { /*...*/ } 使用其他方法。
是否可以保持标准行为并仅覆盖显式键绑定?以及如何做到这一点。
【问题讨论】:
标签: java swing awt keylistener key-bindings