Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to use mnemonics with Actions?  RSS feed

 
Dennis Spathis
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I opt to use Swing Actions, rather than JMenuItems,
in my JMenus, can I still use mnemonics (e.g., Alt-F-N
to trigger the "New" item in the "File" menu)? JMenuItems
have a setMnemonic() method; AbstractActions do not. Is
there a way to do this, or is this just a limitation of
Swing Actions?
Thanks in advance.
D.
 
Dennis Spathis
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I should've mentioned that I'm using JDK 1.2.2.
I know that with 1.3, I should not add Actions directly
to my JMenu but instead create a JMenuItem; use its
setAction() method to configure it; then add it to the
JMenu. But there is no setAction() method prior to 1.3 so
I cannot use that approach.
Any ideas.
D.
 
mick barry
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you use actions, a JMenuItem object is still added to the menu.
If you look at the sig for add you'll see that it returns a JMenuItem:
public JMenuItem add(Action a);
You simply need to set the mneumonic on the returned menuitem:
JMenuItem item = menu.add(action);
item.setMnemonic(...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!