Key Pressed Event
java, jbutton, keylistener, swing
Solution
don't to use `KeyListener` or `MouseListener` for `JButton` or `JButtons JComponent`, those events are implemented in API, or `ButtonsModel`, every can be testable, with to `consume()` of `KeyEvent`
`JButton` has implemented ENTER and SPACE key as accelator in KeyBindings
remove `SPACE` from `KeyBindings`, but not suggest that, I'm wouldn'd be confuse users, sure depends of
Problem
I want add a KeyEventListener to JButton which responds to Enter key, using following code segment: ``` private void jButton3KeyPressed(java.awt.event.KeyEvent evt) { if (evt.getKeyCode() == 10) { eventRegister(); } } ``` I pressed space bar instead of enter and the if condition set to true and the `eventRegister` invoked. Why? How could I prevent this manner?