When I hit the enter key into a JTextField
and I'm pressing one modifier key (like Ctrl or Alt) the ActionEvent
is not fired and thus I can't check the modifier key just pressed.
Why is it a bug?
When I hit the enter key into a JTextField
and I'm pressing one modifier key (like Ctrl or Alt) the ActionEvent
is not fired and thus I can't check the modifier key just pressed.
Why is it a bug?
For Swing widgets, key binding should be done through InputMap
and ActionMap
(although the "obsolete" registerKeyboardAction
is simpler). See Keyboard Bindings in Swing in the old Swing Connection, and the JComponent
API docs.
The Pluggable Look & Feel rather gets in the way of mapping input events onto actions. Exactly what happens with ActionEvent
is up to the current PL&F. Application code directly registering KeyListener
generally isn't a good idea in Swing. Some components are made up of other smaller components, meaning InputEvent
s may or may not get passed on. Input events may get interpreted to perform more than one operation. Generally the whole thing is a mess.