What is the difference between registerKeyboardAction(…) and getInputMap().put(…) + getActionMap().put(…)?

落花浮王杯 提交于 2021-02-07 18:46:29

问题


What is the difference between these two methods:

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

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

and:

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

回答1:


There is no difference, but registerKeyboardAction is obsolete as stated in the javadoc.



来源:https://stackoverflow.com/questions/18673699/what-is-the-difference-between-registerkeyboardaction-and-getinputmap-put

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!