Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Menus and Keyboard shortcuts? 1

Status
Not open for further replies.

BlindPete

Programmer
Jul 5, 2000
711
US
Do I have to add another action listener to use keyboard shortcuts in my menus? Also how do I get the charcter of the short to be underlined.

I figure there is some trick I'm missing. Any help would be greatly appreciated. [sig]<p> Pete<br><a href=mailto:blindpete@mail.com>blindpete@mail.com</a><br><a href= > </a><br>What your mother told you is true! You will go blind! (from moonshine anyway)[/sig]
 
This is what I found that seems to work:


about.setMnemonic(KeyEvent.VK_A);
about.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_A, ActionEvent.ALT_MASK));
about.addActionListener(new AboutHandler());

The above snippet there is an about option, The first line sets the mnemonic to a. The second line sets the shortcut key to alt-A and then the last line is the actionListener that does something when the button is activated by clicking on it, or using the shortcut keys....

Hope this helps...

is where you can check out an example or two. Be warned these are swing applets that require a download of a pluggin that is 1 to 2 Mb in size. Also this is an experimental site. The relavent part of the applet is the information button at the top of the applet. You can also click inside the applet and hit alt-A and that will bring up the about menu....

[sig]<p>Troy Williams B.Eng.<br><a href=mailto:fenris@hotmail.com>fenris@hotmail.com</a><br><a href= > </a><br> [/sig]
 
Thanks :) [sig]<p> Pete<br><a href=mailto:blindpete@mail.com>blindpete@mail.com</a><br><a href= > </a><br>What your mother told you is true! You will go blind! (from moonshine anyway)[/sig]
 
I should have mentioned that KeyEvent.VK_A is a constant representing the string or char (I can't remember which) &quot;a&quot;
so VK_B = b
VK_C = c

etc.
I believe there are more of them but I can't remember the site that listed them. I think it was here


This site will also provide definitions to the setAccelerator and setMnemonic methods.

Good Luck
[sig]<p>Troy Williams B.Eng.<br><a href=mailto:fenris@hotmail.com>fenris@hotmail.com</a><br><a href= > </a><br> [/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top