• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

AbstractAction name with a associated KeyStroke

 
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have implemented a action class, that extends the AbstractAction and also I have associated a KeyStroke with that action.
So for example my OpenNewStuff action is triggered when Ctrl+O is pushed.

My problem is, that I want that the "Ctrl+O" binding information would be reflected in the Actions's name parameter.

Like for example in Firefox browser, when you push the "File" menu in the upper left corner, you see menu items labeled like so:
- New Window [space] Ctrl+N
- New Tab [space] Ctrl+T
- etc. ...

My OpenNewStuff action also is triggered by a menu item component and want the "Ctrl+O" to be added for the menu item's name.
How to do that correctly? Do I really have to set my actions name like that:
putValue(Action.NAME, "Open New Stuff" + " Ctrl+O"));

What about the space between? I think I cannot add "\t" character there.
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What you are referring to, is called an accelerator key.
Check out Action#ACCELERATOR_KEY.
You will need to use it the same way using AbstractAction#putValue(Action.ACCELERATOR_KEY,Object keyValue)
More here on using accelerators.

Typically one uses the following
Action.NAME (just the display text like "Open")
Action.MNEMONIC_KEY (underlined 'O' in Open)
Action.ACCELERATOR_KEY (Ctrl+O)
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The value for MNEMONIC_KEY should be an Integer, e.g. Integer.valueOf('F').
The value for ACCELERATOR_KEY should be a KeyStroke.
And there are also SMALL_ICON and LARGE_ICON_KEY for the icon (both should take an Icon), SHORT_DESCRIPTION for the tooltip (should take a String), and ACTION_COMMAND_KEY for the action command (should take a String). You'll probably won't use the others. Check out the API for more information.
 
Juhan Voolaid
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Awesome! Thank you.
 
reply
    Bookmark Topic Watch Topic
  • New Topic