Fire a JButton with spacebar, or enter key, or mouse click

前端 未结 2 926
我寻月下人不归
我寻月下人不归 2020-12-19 21:25

I\'m trying to get a simple JFrame with a single button to fire an event when any of these events happen:

  • The Enter key is pressed AND the JButton has focus
2条回答
  •  囚心锁ツ
    2020-12-19 22:03

    What you can (and probably should) do is create an AbstractAction. You can use the AbstractAction both for your ActionMap as well as for clicking (do JButton.setAction(...))

提交回复
热议问题