Forums Register Login

How to use mnemonics with Actions?

+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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(...
Of course, I found a very beautiful couch. Definitely. And this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 993 times.
Similar Threads
JMenuItem enable
CardLayout / JPanel Question
mnemonics are not getting focus for the menubar
JMenuItem Accelerators does not work with me
How to pass GUI data to custom Swing actions ?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 02:42:35.