Java Reference
In-Depth Information
public JMenuItem()
JMenuItem jMenuItem = new JMenuItem();
public JMenuItem(Icon icon)
Icon atIcon = new ImageIcon("at.gif");
JMenuItem jMenuItem = new JMenuItem(atIcon);
public JMenuItem(String text)
JMenuItem jMenuItem = new JMenuItem("Cut");
public JMenuItem(String text, Icon icon)
Icon atIcon = new ImageIcon("at.gif");
JMenuItem jMenuItem = new JMenuItem("Options", atIcon);
public JMenuItem(String text, int mnemonic)
JMenuItem jMenuItem = new JMenuItem("Cut", KeyEvent.VK_T);
public JMenuItem(Action action)
Action action = ...;
JMenuItem jMenuItem = new JMenuItem(action);
The mnemonic allows you to select the menu through keyboard navigation. For instance,
you can simply press Alt-T on a Windows platform to select the Cut menu item if the item
appears on an Edit menu that is already open. The mnemonic for a menu item usually appears
underlined within the text label for the menu. However, if the letter doesn't appear within the
text label or if there is no text label, the user will have no visual clue as to its setting. Letters are
specified by the different key constants within the java.awt.event.KeyEvent class.
Other platforms might offer other meta-keys for selecting mnemonics. On UNIX, the
meta-key is also an Alt key; on a Macintosh, it's the Command key.
Note Adding a JMenuItem with a label of “ - ” doesn't create a menu separator as it did with AWT's
MenuItem .
JMenuItem Properties
The JMenuItem class has many properties. Roughly 100 properties are inherited through its
various superclasses. The 10 properties specific to JMenuItem are shown in Table 6-3.
 
Search WWH ::




Custom Search