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.