Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #6913
| From | "John B. Matthews" <nospam@nospam.invalid> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: event listener |
| Date | 2011-08-09 10:38 -0400 |
| Organization | The Wasteland |
| Message-ID | <nospam-A5EA5D.10384109082011@news.aioe.org> (permalink) |
| References | <2e38eb6a-a835-4fdf-bebe-5fc2b4f17333@m4g2000pri.googlegroups.com> |
In article <2e38eb6a-a835-4fdf-bebe-5fc2b4f17333@m4g2000pri.googlegroups.com>, wee <rbulseco@gmail.com> wrote: > I have a JButton object and I added an actionListener to it. It works > well with a mouse click, but if I use the enter key while the focus > is on the JButton, nothing happens. Do I need to add a keypress > listener on top of the actionListener to the JButton so that it would > work both for a keypress and a mouse click? Help on this query is > greatly appreciated. The default key binding for Swing buttons is the space key [1]. You can add a binding to the enter key, as shown here [2], but the root pane's setDefaultButton() method [3] is a convenient alternative. [1]<http://download.oracle.com/javase/tutorial/uiswing/misc/keybinding.html> [2]<http://sites.google.com/site/drjohnbmatthews/keypad-panel> [3]<http://download.oracle.com/javase/6/docs/api/javax/swing/JRootPane.html> -- John B. Matthews trashgod at gmail dot com <http://sites.google.com/site/drjohnbmatthews>
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Find similar
event listener wee <rbulseco@gmail.com> - 2011-08-08 17:17 -0700 Re: event listener "John B. Matthews" <nospam@nospam.invalid> - 2011-08-09 10:38 -0400
csiph-web