• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Hot keys!

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all

Is it possible to have accelerator keys declared and binded to a particular action without using an xml file at some stage. Please help I am stuck with the accelerator keys, I can't get them working.

Thanks in advance!
 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Benjamin!

By accelerator keys, do you mean you want to be able to type ALT+"some other key" to trigger an event? An easy way to set this up is to "cheat" a little and use invisible components. For instance, create a JButton, don't add it to a container, and set its Mnemonic to whatever shortcut key you want. Create an ActionPerformed to handle the event when the shortcut key is pressed, and viola.

Hope this helps!
 
Ranch Hand
Posts: 356
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello,

if the key is associated to a component you can use the mnemonic (see JComponent#setMnemonic, Action#ACCELERATOR_KEY, Action#MNEMONIC_KEY). (In that case it is not an "accelerator key" according to some definitions.)

You can bind almost any key(combination) to any action by using the action map of the root pane of a top level component like JDialog or JFrame:

Kai
[ July 19, 2005: Message edited by: Kai Witte ]
 
Benjamin Malebana
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks guys I do understand your solutions of which are Swing based and I am looking for RCP based solution. Can anyone help me do the MNEMONIC keys in RCP without using the xml file? Thanks in advance.
 
Can you really tell me that we aren't dealing with suspicious baked goods? And then there is this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic