Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Special accelerators keys don't work



Hi,

On 23.07.2007, at 10:00, Emmanuel Puybaret wrote:
Hi, 

Thank you for your answers about special accelerators keys.
It looks like there's no really satisfying solution. :(

you can use following code:

class SymAction extends AbstractAction
{
public SymAction(String actionCom, int keyCode, int keyMask)
{
super(actionCom);
int shortcutKeyMask = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke(keyCode, keyMask | shortcutKeyMask));
}

public void actionPerformed(ActionEvent e)
{
System.out.println("SymAction.actionPerformed() : "+e.getActionCommand());
}
}

...
JMenu menu = new JMenu("The Menu");
SymAction sym = new SymAction("Add Something", KeyEvent.VK_ADD, 0);
JMenuItem mi = new JMenuItem(sym);
mi.setActionCommand("Add Something COMMAND");
menu.add(mi);
...

At least this works with the Command- "+" on extended keyboard or with Num-pad ON for MacBook keyboards.

Looks like it only works when you create a "AbstractAction" and set the accelerator with putValue(...).


Regards
Robert

--------------------------------------------------------------------------------------
Robert Straub            E email@hidden
--------------------------------------------------------------------------------------



 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden

References: 
 >Re: Special accelerators keys don't work (From: Emmanuel Puybaret <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.