Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > event listener

Reply
Thread Tools

event listener

 
 
wee
Guest
Posts: n/a
 
      08-09-2011
hi,

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.

thanks..
 
Reply With Quote
 
 
 
 
John B. Matthews
Guest
Posts: n/a
 
      08-09-2011
In article
<(E-Mail Removed)>,
wee <(E-Mail Removed)> 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>
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
having trouble with event listener: detect iframe close event fromparent Mike Scirocco Javascript 4 04-05-2007 03:19 AM
Java Event Listener integer problem. Mmm_moo_cows Java 4 10-26-2004 03:26 PM
event listener requesting a thread Shrish Java 1 10-16-2004 09:10 AM
Event listener list implementation Slobodan C Java 2 01-23-2004 09:00 PM
SERVLETS: extending j_security_check - filter or event listener? Sasha Borodin Java 0 07-28-2003 08:22 PM



Advertisments