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

StackOverflow https://stackoverflow.com/questions/18673699

سؤال

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);
هل كانت مفيدة؟

المحلول

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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top