buoy.widget

Class BMenuItem

Implemented Interfaces:
MenuWidget
Known Direct Subclasses:
BCheckBoxMenuItem, BRadioButtonMenuItem

public class BMenuItem
extends Widget
implements MenuWidget

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:

Author:
Peter Eastman

Constructor Summary

BMenuItem()
Create a new BMenuItem with no label.
BMenuItem(String text)
Create a new BMenuItem.
BMenuItem(String text, Icon image)
Create a new BMenuItem.
BMenuItem(String text, Shortcut shortcut)
Create a new BMenuItem.
BMenuItem(String text, Shortcut shortcut, Icon image)
Create a new BMenuItem.

Method Summary

String
getActionCommand()
Get the "action command" which will be sent in a CommandEvent when this menu item is selected.
JMenuItem
getComponent()
Icon
getIcon()
Get the image which appears next to this menu item.
int
getMnemonic()
Get the mnemonic which can be used to activate this menu item in keyboard navigation mode.
Shortcut
getShortcut()
Get the keyboard shortcut for this menu item.
String
getText()
Get the text which appears on this menu item.
void
setActionCommand(String command)
Set the "action command" which will be sent in a CommandEvent when this menu item is selected.
void
setIcon(Icon image)
Set the image which appears next to this menu item.
void
setMnemonic(int key)
Set the mnemonic which can be used to activate this menu item in keyboard navigation mode.
void
setShortcut(Shortcut shortcut)
Set the keyboard shortcut for this menu item.
void
setText(String title)
Set the text which appears on this menu item.

Methods inherited from class buoy.widget.Widget

addEventLink, dispatchEvent, getBackground, getBounds, getComponent, getCursor, getFont, getMaximumSize, getMinimumSize, getName, getParent, getPreferredSize, hasFocus, isEnabled, isFocusable, isVisible, repaint, requestFocus, setBackground, setCursor, setEnabled, setFocusable, setFont, setName, setVisible

Methods inherited from class buoy.event.EventSource

addEventLink, addEventLink, addEventLink, dispatchEvent, removeEventLink

Constructor Details

BMenuItem

public BMenuItem()
Create a new BMenuItem with no label.

BMenuItem

public BMenuItem(String text)
Create a new BMenuItem.
Parameters:
text - the text to display on the BMenuItem

BMenuItem

public BMenuItem(String text,
                 Icon image)
Create a new BMenuItem.
Parameters:
text - the text to display on the BMenuItem
image - the image to display next to the menu item

BMenuItem

public BMenuItem(String text,
                 Shortcut shortcut)
Create a new BMenuItem.
Parameters:
text - the text to display on the BMenuItem
shortcut - a keyboard shortcut which will activate this menu item

BMenuItem

public BMenuItem(String text,
                 Shortcut shortcut,
                 Icon image)
Create a new BMenuItem.
Parameters:
text - the text to display on the BMenuItem
shortcut - a keyboard shortcut which will activate this menu item
image - the image to display next to the menu item

Method Details

getActionCommand

public String getActionCommand()
Get the "action command" which will be sent in a CommandEvent when this menu item is selected.

getComponent

public JMenuItem getComponent()
Overrides:
getComponent in interface Widget

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.
Returns:
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.
Parameters:
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.

Written by Peter Eastman.