Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EnterKey to switch panels

 
Joe Groves
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey i have a tiny problem...

i need to have my program react to the enter key to switch from one panel to another
any one know how i can do this?
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Likes 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
KeyBindings

or, if you already have a button thast does the job, set the button as the default button
 
Randall Twede
Ranch Hand
Posts: 4442
3
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
from what i can see it looks the same as handling other events. import KeyEvent and KeyListener. implement Keylistener or use a seperate listener class. write the 3 methods of KeyListener.
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 been typed.
tip: some methods can be do nothing methods.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> import KeyEvent and KeyListener. implement Keylistener or use a seperate listener class

let's say there's 10 focusable components displayed.
are you going to add keyListeners to each?
 
Randall Twede
Ranch Hand
Posts: 4442
3
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
actually i havent listened to keys much. only a few homeworks that did this:
programMenu.setMnemonic( KeyEvent.VK_P );
and the professor actually wrote that part for us.
is that what keybinding is?
well i can google it
KeyBindings
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic