aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Button keyboard event Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Button keyboard event" Watch "Button keyboard event" New topic
Author

Button keyboard event

Matthew Cohen
Greenhorn

Joined: Oct 19, 2001
Posts: 1
I have a frame that contains a panel with a button.
How can I make it so that if the user presses enter, the button is automatically activated. If tried to no avail to requestFocus to the button.
Thanks
Kris Philippaerts
Greenhorn

Joined: Oct 19, 2001
Posts: 25
You have to catch the keypress. And it depends on the element that has the focus how to do this. If fact, you should add a KeyListener to all elements that can possibly have the focus.
The KeyListener should override the following methods:
void keyPressed(KeyEvent e)
Invoked when a key has been pressed.
void keyReleased(KeyEvent e)
Invoked when a key has been released.
void keyTyped(KeyEvent e)
Invoked when a key has
In the method keyPressed you can then check for an enter to be pressed.
HTH,
Kris Philippaerts
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Button keyboard event
 
Similar Threads
Accessing methods HELP!
Not drawing the Button?
Popup window close button
tuna hot dish
WA #1.....word association