A BMenuItem is a Widget corresponding to an item in a pulldown menu. Each menu item typically
represents a different command, which the user can issue by selecting it with the mouse.
It also is possible to select a menu item with the keyboard. There are, in fact, two different
ways of doing this. First, a menu item may have a
Shortcut
associated with it.
This is a particular combination of keys, usually including a platform specific modifier key
such as Control or Meta. Whenever that combination of keys is pressed, the corresponding menu item
is immediately selected.
Second, many platforms allow keyboard navigation of menus and menu items. Typically, a user enters
keyboard navigation mode by pressing a particular key. They can then use arrow keys to select a
desired menu item, and Enter or Space to activate it. Keyboard navigation can be accelerated by
assigning a
mnemonic to each menu and menu item. When the user is in keyboard navigation
mode, pressing the mnemonic key for a particular menu item will immediately select that item.
In addition to the event types generated by all Widgets, BMenuItems generate the following event types:
BMenuItem
public BMenuItem()
Create a new BMenuItem with no label.
BMenuItem
public BMenuItem(String text)
Create a new BMenuItem.
text
- the text to display on the BMenuItem
BMenuItem
public BMenuItem(String text,
Icon image)
Create a new BMenuItem.
text
- the text to display on the BMenuItemimage
- the image to display next to the menu item
BMenuItem
public BMenuItem(String text,
Shortcut shortcut)
Create a new BMenuItem.
text
- the text to display on the BMenuItemshortcut
- a keyboard shortcut which will activate this menu item
BMenuItem
public BMenuItem(String text,
Shortcut shortcut,
Icon image)
Create a new BMenuItem.
text
- the text to display on the BMenuItemshortcut
- a keyboard shortcut which will activate this menu itemimage
- the image to display next to the menu item
getActionCommand
public String getActionCommand()
Get the "action command" which will be sent in a CommandEvent when this menu item is selected.
getIcon
public Icon getIcon()
Get the image which appears next to this menu item.
getMnemonic
public int getMnemonic()
Get the mnemonic which can be used to activate this menu item in keyboard navigation mode.
- the key code (defined by the KeyEvent class) which activates this menu item
getShortcut
public Shortcut getShortcut()
Get the keyboard shortcut for this menu item.
getText
public String getText()
Get the text which appears on this menu item.
setActionCommand
public void setActionCommand(String command)
Set the "action command" which will be sent in a CommandEvent when this menu item is selected.
setIcon
public void setIcon(Icon image)
Set the image which appears next to this menu item.
setMnemonic
public void setMnemonic(int key)
Set the mnemonic which can be used to activate this menu item in keyboard navigation mode.
key
- the key code (defined by the KeyEvent class) which activates this menu item
setShortcut
public void setShortcut(Shortcut shortcut)
Set the keyboard shortcut for this menu item.
setText
public void setText(String title)
Set the text which appears on this menu item.