my dog learned polymorphism*
The moose likes Swing / AWT / SWT and the fly likes setMnemonic(int) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "setMnemonic(int)" Watch "setMnemonic(int)" New topic
Author

setMnemonic(int)

Karen Baog
Ranch Hand

Joined: Mar 02, 2005
Posts: 120
Could someone please provide a sample code using the setMnemonic(int).
What does the int parameter refer to?


amerzil co-ed student<br />"Praise be the Code"
Steve Morrow
Ranch Hand

Joined: May 22, 2003
Posts: 657

From the API:
A mnemonic must correspond to a single key on the keyboard and should be specified using one of the VK_XXX keycodes defined in java.awt.event.KeyEvent. Mnemonics are case-insensitive, therefore a key event with the corresponding keycode would cause the button to be activated whether or not the Shift modifier was pressed.


Example:

Tutorial: How to Use Buttons, Check Boxes, and Radio Buttons
Karen Baog
Ranch Hand

Joined: Mar 02, 2005
Posts: 120
If I have:

JMenuItem fileMenu = new JMenuItem("File");

And I want to have the first character underlined.
I could do .setMnemonic('F');

...but this is obsolete.
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

setMnemonic(KeyEvent.VK_F);

http://java.sun.com/j2se/1.5.0/docs/api/java/awt/event/KeyEvent.html


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Steve Morrow
Ranch Hand

Joined: May 22, 2003
Posts: 657

Originally posted by Karen Baog:
If I have:

JMenuItem fileMenu = new JMenuItem("File");

And I want to have the first character underlined.
I could do .setMnemonic('F');

...but this is obsolete.


A mnemonic must correspond to a single key on the keyboard and should be specified using one of the VK_XXX keycodes defined in java.awt.event.KeyEvent.
[ April 08, 2005: Message edited by: Steve Morrow ]
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Moving to Swing/AWT...


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: setMnemonic(int)