Why doesn pressing the Enter key activate the default button on a Swing dialog?
Ans : The default keymap for Swing text components (derived from JTextComponent) binds the Enter key (VK_ENTER) to the ActionEvent for text fields. This was done to be compatible with the behavior of java.awt.Textfield. To enable use of the Enter key to activate the default button, remove the Enter key binding from the default text component keymap as follows: static { KeyStroke enter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0); Keymap map = JTextComponent.getKeymap(JTextComponent.DEFAULT_KEYMAP); map.
Related Questions
- Why when I have received my activation key and go into Licence Control the Activate button is greyed out on my Windows Vista or Windows 7 machine?
- How do I make a GtkEntry widget activate on pressing the Return key?How do I make a GtkEntry widget activate on pressing the Return key?
- Why doesn pressing the Enter key activate the default button on a Swing dialog?