Change ENTER Key function

前端 未结 1 1230
面向向阳花
面向向阳花 2021-01-23 11:09

I wanted to change the default action of the ENTER key on JTable, so I used this code:

table.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONE         


        
相关标签:
1条回答
  • 2021-01-23 11:45

    The default Action for the ENTER key is "selectNextRowCell". As shown here, you can obtain a reference to the original Action and evoke in your new handler.

    String name = "selectNextRowCell";
    Action action = table.getActionMap().get(name);
    …
    public void actionPerformed(ActionEvent ae) {
        action.actionPerformed(new ActionEvent(table, ActionEvent.ACTION_FIRST, name));
    }
    
    0 讨论(0)
提交回复
热议问题