• Post Reply Bookmark Topic Watch Topic
  • New Topic

Hot keys!  RSS feed

 
Benjamin Malebana
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • 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!
 
Darrin Cartwright
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • 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!
 
Kai Witte
Ranch Hand
Posts: 356
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!