• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java swing jbutton shortcut key

 
Sri Vijay
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
KeyboardFocusManager.getCurrentKeyboardFocusManager()
.addKeyEventDispatcher(new KeyEventDispatcher() {
public boolean dispatchKeyEvent(KeyEvent e) {
int c=e.getKeyCode();
if(c==KeyEvent.VK_F2)
{
joptionpane.showmessageDailogue(null,"Clicked");
}
};


This command is working, but if i press the f2 key the message box is coming even already a message box is already available,it shows a message box on the top of the old message box,so if i press two times f2 key two message box are coming is ther any solution for this



thank you

regards
SriVijay
 
Rob Spoor
Sheriff
Pie
Posts: 20608
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use a key binding instead. This way, the modal dialog will block access to the frame and therefore also its key bindings. Check out the Sun/Oracle tutorial for more info.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic