Computer Science Canada

Java Menu Action Masks

Author:  copthesaint [ Fri May 27, 2011 3:03 pm ]
Post subject:  Java Menu Action Masks

Im just wondering, When you create a menu item, eg:

Java:
menuItem = new JMenuItem("Launch", KeyEvent.VK_A);
menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, ActionEvent.CTRL_MASK)); //Important line of code :)
menuItem.getAccessibleContext().setAccessibleDescription("This doesn't really do anything yet");
menu.add(menuItem);


What can I use just to set the accelerator as 'A' for example. without a meta, Shift Crtl mask.

Author:  Tony [ Fri May 27, 2011 3:22 pm ]
Post subject:  RE:Java Menu Action Masks

http://download.oracle.com/javase/6/docs/api/javax/swing/KeyStroke.html

Author:  copthesaint [ Sat May 28, 2011 12:37 am ]
Post subject:  RE:Java Menu Action Masks

Doesnt help me, already looked at page before I posted this. Bump
How would I do this for F1?

Author:  Tony [ Sat May 28, 2011 1:07 am ]
Post subject:  Re: Java Menu Action Masks

so you are using
code:

static KeyStroke        getKeyStroke(Character keyChar, int modifiers)
          Returns a shared instance of a KeyStroke that represents a KEY_TYPED event for the specified Character object and a set of modifiers.

but...
copthesaint @ Fri May 27, 2011 3:03 pm wrote:
What can I use just to set the accelerator as 'A' for example. without a meta, Shift Crtl mask.

and so the linked page also specifies
code:

static KeyStroke        getKeyStroke(char keyChar)
          Returns a shared instance of a KeyStroke that represents a KEY_TYPED event for the specified character.


unless I'm misinterpreting something...

Author:  copthesaint [ Sun May 29, 2011 4:31 pm ]
Post subject:  Re: Java Menu Action Masks

No I was using
Java:
getKeyStroke(int keyCode, int modifiers)
but now looking at it I thought "I bet this is an extremly easy problem to fix if I check KeyEvent" surly enough super easy: getKeyText(int keyCode) So I fixed it from

Java:
menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, ActionEvent.CTRL_MASK));
//too
menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.getKeyText(KeyEvent.VK_A)));


I need to pay more attention -_-. thnx for helping anyways Smile I found my answer from what u said.


: