3

CLARIFICATION: Is there a easy/simple way to change the default mask (ALT on my system) so that things like JMenu's don't, by-default, utilize the default mask + mnemonic (ALT + VK_A, for example) for access? Or is this something that should only be done via custom keybindings?

The default mouse-less modifier is ALT, and is defined (I believe) by the Look-n-Feel. As much as I've heard, defining a unique Look-n-Feel is not trivial, and so it's not something I'm ready to approach.

However, I'm wondering if there's a simple or easily-accessible way to modify the default mouse-less modifier to something other than ALT.

I'm working through the Java tutorials and noted that the default mouse-less modifier applies to menu's, and I couldn't find a way to change that to something else (is there a way to perhaps set an ActionEvent Mask to shift/ctrl which would override the use of ALT?).

Azoreo
  • 236
  • 1
  • 3
  • 14

2 Answers2

2

What you are talking about here, is "mnemonics", if I understand correctly. You can create key bindings that use whatever qualifier you need using the KeyStroke class. Is it important to change the mnemonic qualifier?

Also, see this question for more information.

update

I'm on a Mac/OS X, so I never looked much into mnemonics, but have a look at the source code for the WindowsLookAndFeel and BasicLookAndFeel (the base class for most LAFs) classes. I found a property in BasicLookAndFeel that looked promising: "Menu.shortcutKeys", with the default value new int[] {KeyEvent.ALT_MASK}. Try setting it to something else, and see if it works..

Community
  • 1
  • 1
Harald K
  • 26,314
  • 7
  • 65
  • 111
  • Yep, it's mnemonics and masks. Specifically I'm wondering if there's a simple way to change the mask used to access Java menu's (out of curiosity, not necessity). They appear to use the default mask (ALT on my system). While things like JMenuItems have Accelerators which will accept a KeyStroke, setMnemonic only accepts KeyEvents unless I've missed a way to force a KeyStroke in there. Custom keybindings are something I should check out and the question you linked was helpful. – Azoreo Jun 24 '13 at 12:49
  • Ahhh, that update sounds interesting - I'll look into it, thanks Harald. – Azoreo Jun 24 '13 at 21:30
1

As this key varies my platform, the Toolkit class includes a getMenuShortcutKeyMask() that "Determines which modifier key is the appropriate accelerator key for menu shortcuts." There's a complete example here. See also How to Use Menus.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045