标签云

微信群

扫码加入我们

WeChat QR Code


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

2018年09月27日16分01秒

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

2018年09月26日16分01秒

But JFrame does not have a getInputMap or getActionMap method

2018年09月26日16分01秒

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

2018年09月26日16分01秒

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.

2018年09月26日16分01秒

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

2018年09月26日16分01秒

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

2018年09月26日16分01秒

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

2018年09月27日16分01秒

don't quite understand - reason for what?

2018年09月26日16分01秒

Why is registerKeyboardAction() obselete

2018年09月26日16分01秒

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.

2018年09月26日16分01秒