Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

setMnemonic(int)

 
Karen Baog
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could someone please provide a sample code using the setMnemonic(int).
What does the int parameter refer to?
 
Steve Morrow
Ranch Hand
Posts: 657
Clojure Spring VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
setMnemonic(KeyEvent.VK_F);

http://java.sun.com/j2se/1.5.0/docs/api/java/awt/event/KeyEvent.html
 
Steve Morrow
Ranch Hand
Posts: 657
Clojure Spring VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to Swing/AWT...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic