Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Swing / AWT / SWT and the fly likes Mnemonic question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Mnemonic question" Watch "Mnemonic question" New topic

Mnemonic question

Meyer Florian
Ranch Hand

Joined: Oct 20, 2003
Posts: 62
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

Joined: Jun 02, 2002
Posts: 22
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

Joined: Jun 02, 2003
Posts: 16
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).
I agree. Here's the link:
subject: Mnemonic question
jQuery in Action, 3rd edition