Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Mnemonic question

 
Meyer Florian
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey there!
I have a JButton and called setMnemonic(KeyEvent.VK_ENTER); on it. But the button won't be invoked when I press the enter-key. When I set the mnemonic shortcut to 'b' or something else, it doesn't work either. The JButton is inside of a JPanel which is inside of a JDialog.
Thanks for help
Florian Meyer
 
Daniel Puryear
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What Listener interfaces have you implemented? If you want to work at the VK_ENTER level, use the KeyListener. If you want to work at the symantic level, use the ActionListener...
 
Brian Knight
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does the text on your button actually have a 'b' in it? Setting the mnemonic to enter won't work, as you should rather register a keyboard action if this is the key you wish to use, or look at setDefaultCapable() on JButton (Key stroke would then depend on your current look and feel). If you wish to use mnemonics the char you set as the mnemonic should be contained in the text of you button for it to work properly (and for it to make sense to the user).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic