java – registerKeyboardAction(…)和getInputMap()之间有什么区别.put(…)getActionMap().put(…)?

这两种方法有什么区别:

getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(
       "pressed F10"), "someAction");

getActionMap().put("someAction", new AbstractAction() {
     @Override
     public void actionPerformed(ActionEvent e) {
          //Do something
     }
});

和:

registerKeyboardAction(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
        //Do something
    }
}, KeyStroke.getKeyStroke("pressed F10"), JComponent.WHEN_FOCUSED);

最佳答案 没有区别,但registerKeyboardAction已经过时,如javadoc中所述.

点赞