Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / April 2004

Tip: Looking for answers? Try searching our database.

Two KeyBindings for one Action

Thread view: 
harald ebert - 26 Apr 2004 15:00 GMT
Hello,

I want an Action to have 2 KeyBindings.

First the minus sign from the KeyPad,
second the minus sign from the NumPad.

public class MyAction extends AbstractAction {
 
 public MyAction() {
   super(parent, "MyAction");
   putValue(ACCELERATOR_KEY,
            KeyStroke.getKeyStroke(KeyEvent.VK_MINUS,
                                   InputEvent.CTRL_MASK));
 }

 public void actionPerformed(java.awt.event.ActionEvent e) { }
 
}

I looked at the code of AbstractAction and the design of the Actions
property table allows, as far as I can see, only one accelerator key,
i.e. setting a second KeyStroke replaces the previously set one.

Does anybody know whether it is possible to have two KeyStrokes for on
Action?
Where can I find some information on how to?
Or do I have to use other mechanisms to get this to work?

Thanks for your help

Harald Ebert
ak - 26 Apr 2004 18:13 GMT
> I want an Action to have 2 KeyBindings.
>
[quoted text clipped - 22 lines]
> Where can I find some information on how to?
> Or do I have to use other mechanisms to get this to work?

may be you could use 2 Actions each with different key bindings but with
same actionPerformed()?

--

____________

http://reader.imagero.com the best java image reader.
harald ebert - 29 Apr 2004 15:10 GMT
> > I want an Action to have 2 KeyBindings.
>
> may be you could use 2 Actions each with different key bindings but with
> same actionPerformed()?

Sorry for the late answer. Haven't been in office for two days.

Yes, I think it would work, although it is not nice, since i would
have to add an additional button (hidden) to the panel and assign the
second action to the hidden additional button in order to introduce
the additional action to the KeyBinding handler. This is at least my
understanding on how actions work.

Thanks.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.