Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / August 2006

Tip: Looking for answers? Try searching our database.

awt event, how to make all button listen to 3 keys

Thread view: 
John_Woo - 05 Aug 2006 19:51 GMT
Hi,

The JButton by default is associated with the key "space bar", pressing
that key same as clicking mouse on it.

I have a swing app which has muli-panels and buttons. I'm wondering how
to make the two "Enter" keys triger button's action as well.

--
Thanks
John
Toronto
Steve W. Jackson - 07 Aug 2006 19:04 GMT
> Hi,
>
[quoted text clipped - 8 lines]
> John
> Toronto

The association with the "space bar" should only apply when a button has
focus.  Pressing the space bar when some other component holds focus
won't invoke your button.

I believe your second item can be resolved by setting a button as
default.  Every JFrame, JDialog, etc., has a JRootPane.  You can then
call that item's getRootPane() method to retrieve it, and then call its
setDefaultButton(JButton) method.  That causes the button to take on a
special appearance, and to respond automatically to pressing
Enter/Return while the dialog has focus.

= Steve =
Signature

Steve W. Jackson
Montgomery, Alabama



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.