简体   繁体   English

更改ENTER键功能

[英]Change ENTER Key function

I wanted to change the default action of the ENTER key on JTable , so I used this code: 我想在JTable上更改ENTER键的默认操作,所以我使用了这段代码:

table.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
        .put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "Enter");
table.getActionMap().put("Enter", new AbstractAction() {
    private static final long serialVersionUID = 1L;
    public void actionPerformed(ActionEvent ae) {
        //my action
    }
}

Tt works normally. Tt正常工作。 What I want now is to change the row just after my action. 我现在想要的是在我的行动之后改变行。 In other words, execute the default action of the enter key. 换句话说,执行enter键的默认操作。

The default Action for the ENTER key is "selectNextRowCell" . ENTER键的默认Action"selectNextRowCell" As shown here , you can obtain a reference to the original Action and evoke in your new handler. 如图所示在这里 ,你可以得到原来的参考Action ,并在新的处理程序唤起。

String name = "selectNextRowCell";
Action action = table.getActionMap().get(name);
…
public void actionPerformed(ActionEvent ae) {
    action.actionPerformed(new ActionEvent(table, ActionEvent.ACTION_FIRST, name));
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM