Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Java Menu Action Masks
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
copthesaint




PostPosted: 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.
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: 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
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
copthesaint




PostPosted: 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?
Tony




PostPosted: 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...
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
copthesaint




PostPosted: 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.
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: