Binding Mnemonics to Node Actions

In yesterday's blog entry, you saw most/all Actions relevant to Nodes demonstrated within the context of a single sample:

However, what you do NOT see, in the screenshot above, are mnemonics. In other words, maybe you'd like to let the user use a single character on the keyboard (which is not the same as a keyboard shortcut) to invoke the various Actions shown above? If that support were present, you'd see a character in the items above underlined, indicating which key on the keyboard should be pressed to invoke the Action.

As luck would have it (or, in fact, as JDeveloper would have it!), it is now possible (i.e., in 7.1 and onwards, already in 7.1 Beta as well), to enable mnemonics in the above scenario.

This information should be no surprise to anyone who has read the NetBeans API Changes document, where you'll see this line:

(Jun 14 '11) org-openide-awt: Turn on Mnemonics in Popup Menus

As a result, you can change the sample to show mnemonics which, when the underlined character is pressed on the keyboard, will cause the underlying Action to be invoked:

Notice that the latter two Actions above appear not to have mnemonics defined. (That's not a problem, just brand the display text, adding an ampersand before the character that you'd like to be the mnemonic.) I.e., the Action needs to define its own mnemonic and, if it is defined, the mnemonic can now, for the first time, be displayed and used to invoke the underlying Action.

Here's what you need to define to enable the mnemonic for the Actions of a Node:

Rather than creating the whole folder structure yourself, right-click the application, choose Branding, go to Resource Bundles, and then search for "USE_MNEMONICS". You'll then be able to brand the value right within the GUI, without needing to go into the folder/file structure you see above.


Sorry for a bit noob question, but can I change those menu entries (write there ampersand to have mnemonics)? I can do it in my custom action, but not in these, when I have no annotations.

Posted by Mvek on February 07, 2012 at 12:15 PM PST #

Post a Comment:
  • HTML Syntax: NOT allowed

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.


« June 2016