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