默认行为右箭头输入键Jtable
•浏览 1
Default behaviour right arrow to enter key Jtable
我正在用 swing 和 Jtable 编写应用程序,我需要默认行为从右箭头到 enter 键,按 Enter 键移动到右侧单元格。
我已经看到如何用这个方法覆盖输入的默认行为:
private void createKeybindings(JTable table) {
table.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0),"Enter");
table.getActionMap().put("Enter", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent ae) {
}
});
}
KeyStroke existingKeyStroke = KeyStroke.getKeyStroke("RIGHT");
KeyStroke addedKeyStroke = KeyStroke.getKeyStroke("ENTER");
InputMap im = component.getInputMap(...);
im.put(addedKeyStroke, im.get(existingKeyStroke));
但是我不知道如何在actionPerfomed中传输右箭头进入键的行为,用于向右移动按Enter。有什么想法吗?
谢谢
不要覆盖 Enter 键的默认行为。
只需使用 Enter 键共享右箭头操作:
与不同的 KeyStroke 共享 Action 的基本代码:
private void createKeybindings(JTable table) {
table.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0),"Enter");
table.getActionMap().put("Enter", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent ae) {
}
});
}
KeyStroke existingKeyStroke = KeyStroke.getKeyStroke("RIGHT");
KeyStroke addedKeyStroke = KeyStroke.getKeyStroke("ENTER");
InputMap im = component.getInputMap(...);
im.put(addedKeyStroke, im.get(existingKeyStroke));