【问题标题】:Default behaviour right arrow to enter key Jtable默认行为右箭头输入键 Jtable
【发布时间】:2015-01-09 22:00:25
【问题描述】:

我在 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) {
            }
        });
    }

但我不知道如何在 actionPerfomed 中传输右箭头进入键的行为,以便向右移动按 Enter。有什么想法吗?

谢谢

【问题讨论】:

    标签: java swing jtable keystroke


    【解决方案1】:

    不要覆盖 Enter 键的默认行为。

    只需使用 Enter 键共享右箭头操作:

    与不同 KeyStroke 共享 Action 的基本代码:

    KeyStroke existingKeyStroke = KeyStroke.getKeyStroke("RIGHT");
    KeyStroke addedKeyStroke = KeyStroke.getKeyStroke("ENTER");
    InputMap im = component.getInputMap(...);
    im.put(addedKeyStroke, im.get(existingKeyStroke));
    

    【讨论】:

      猜你喜欢
      • 2016-12-19
      • 2011-09-07
      • 2010-11-08
      • 1970-01-01
      • 2014-01-19
      • 1970-01-01
      • 2022-07-15
      • 2021-11-19
      • 1970-01-01
      相关资源
      最近更新 更多