Two Laptop Bag
The moose likes Swing / AWT / SWT and the fly likes Mnemonics in a JButton Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Mnemonics in a JButton" Watch "Mnemonics in a JButton" New topic

Mnemonics in a JButton

Christopher C. Cook

Joined: Jul 08, 2002
Posts: 1
Hi all,
I was wondering if anyone could tell me how to make a mnemonic work without using Alt in a metal-feel application. I am building an app in which the users want to hit PF9 to activate a button on the GUI. Any ideas how to set this mnemonic?
Thanks a lot.
Rene Liebmann
Ranch Hand

Joined: May 02, 2002
Posts: 196
Hi Christopher,
welcome to JavaRanch. Your requested feature doesn't work with a Mnemonic, because a mnemonic consists of the ALT button and a letter, which is part of the buttons text, but there are lots of workarounds possible.
One thing, which I like is a non visible JMenuItem. This can have your requested button as an Accelerator.
Another possibility is, that your main application (JFrame) listens for all key events and if PF9 is pressed, then you can do your action.
But it will not work if your JButton will listen for PF9.
Hope that helps
subject: Mnemonics in a JButton
It's not a secret anymore!