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 / GUI / June 2004

Tip: Looking for answers? Try searching our database.

Accelerator

Thread view: 
ice - 24 Jun 2004 17:30 GMT
Hi all!

I'm newbie in swing programming...
I've a "Ok" button (JButton) that once pressed does something. I'd like
doing the same thing when a keyboard key is pressed (enter key, in this
case)
I've tried like this:

buttonOk.addActionListener(this);
buttonOk.setMnemonic(KeyEvent.VK_ENTER);

but method actionPerformes is only invoked by mouse click over button and
not by enter-key too

Thanks in advance!
Adam Guillot - 24 Jun 2004 19:17 GMT
> Hi all!
>
[quoted text clipped - 11 lines]
>
> Thanks in advance!

Your swing class have to implements KeyListener (I think it did)
and you have to set a method void keyPressed(KeyEvent evt)
look the java api and/or java almanac for code sample
Roedy Green - 24 Jun 2004 21:54 GMT
>Your swing class have to implements KeyListener (I think it did)
>and you have to set a method void keyPressed(KeyEvent evt)
>look the java api and/or java almanac for code sample

see http://mindprod.com/products.html#KEYPLAYER
for sample code.

Signature

Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.

Jim Sculley - 24 Jun 2004 23:30 GMT
> Hi all!
>
[quoted text clipped - 9 lines]
> but method actionPerformes is only invoked by mouse click over button and
> not by enter-key too

Read the documentation:

====================
Sets the keyboard mnemonic on the current model. The mnemonic is the key
which when combined with the look and feel's mouseless modifier (usually
Alt) will activate this button if focus is contained somewhere within
this button's ancestor window.

===================

Note the bit about 'when combined with the look and feel's mouseless
modifier'.

Jim S.

Signature

Remove my extraneous mandibular appendages to reply via email.

ice - 26 Jun 2004 19:21 GMT


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.