标签云

微信群

扫码加入我们

WeChat QR Code


+1 The best, easiest answer I have found. I will upvote this x1000

2019年02月23日03分57秒

x1001 would be better, that way he'd at least get an upvote.

2019年02月22日03分57秒

But JFrame does not have a getInputMap or getActionMap method

2019年02月22日03分57秒

Can'tTell JFrame is not a JComponent. These methods need to be called on components within the top-level window.

2019年02月22日03分57秒

For an example of the first solution: window.getRootPane().registerKeyboardAction(save.getActionListeners()[0], KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.CTRL_MASK), JComponent.WHEN_IN_FOCUSED_WINDOW); Replace save with the name of your JButton, and window with the name of your JFrame.

2019年02月22日03分57秒

Not the simplest solution, but definitely the most elegant and reliable one.

2019年02月22日03分57秒

no, that's outdated api (superceded by actionMap/inputMap since jdk 1.2 or 1.3 - way back in stone age)

2019年02月22日03分57秒

kleopatra Hmm. Thanks for the comment. I want to know the reason. I didn't find it!

2019年02月23日03分57秒

don't quite understand - reason for what?

2019年02月22日03分57秒

Why is registerKeyboardAction() obselete

2019年02月22日03分57秒

Please, see the javadoc (JComponent.registerKeyboardAction(java.awt.event.ActionListener, java.lang.String, javax.swing.KeyStroke, int)): This method is now obsolete, please use a combination of getActionMap() and getInputMap() for similiar behavior.

2019年02月23日03分57秒