MenuItem
, or one of its subclasses.
The default MenuItem
object embodies
a simple labeled menu item.
This picture of a menu bar shows five menu items:
The first two items are simple menu items, labeled
"Basic"
and "Simple"
.
Following these two items is a separator, which is itself
a menu item, created with the label "-"
.
Next is an instance of CheckboxMenuItem
labeled "Check"
. The final menu item is a
submenu labeled "More Examples"
,
and this submenu is an instance of Menu
.
When a menu item is selected, AWT sends an action event to
the menu item. Since the event is an
instance of ActionEvent
, the processEvent
method examines the event and passes it along to
processActionEvent
. The latter method redirects the
event to any ActionListener
objects that have
registered an interest in action events generated by this
menu item.
Note that the subclass Menu
overrides this behavior and
does not send any event to the frame until one of its subitems is
selected.
Modifier and Type | Class and Description |
---|---|
protected class | MenuItem.
Inner class of MenuItem used to provide default support for accessibility. |
Modifier and Type | Field and Description |
---|---|
private volatile String | actionCommand
This field indicates the command that has been issued by a particular menu item. |
private transient volatile ActionListener | |
private static final String | |
private volatile boolean | enabled
A value to indicate whether a menu item is enabled or not. |
pack-priv volatile long | eventMask
The eventMask is ONLY set by subclasses via enableEvents. |
pack-priv volatile String | label
|
private int | menuItemSerializedDataVersion
Menu item serialized data version. |
private static int | |
private static final long | serialVersionUID
Use serialVersionUID from JDK 1.1 for interoperability.
|
private volatile MenuShortcut | shortcut
A sequence of key stokes that ia associated with a menu item. |
Access | Constructor and Description |
---|---|
public | |
public | |
public | MenuItem(String
the label for this menu item. label, MenuShortcut the instance of s)MenuShortcut
associated with this menu item.Create a menu item with an associated keyboard shortcut. |
Modifier and Type | Method and Description |
---|---|
public synchronized void | addActionListener(ActionListener
the action listener. l)Adds the specified action listener to receive action events from this menu item. |
public void | |
pack-priv String | constructComponentName()
Construct a name for this MenuComponent.
|
public void | |
pack-priv void | |
public synchronized void | |
protected final void | disableEvents(long
the event mask defining the event types eventsToDisable)Disables event delivery to this menu item for events defined by the specified event mask parameter. |
pack-priv void | |
public synchronized void | |
public void | enable(boolean
if b)true , enables this menu item;
otherwise disables
Deprecated
As of JDK version 1.1,
replaced by
Sets whether or not this menu item can be chosen.
setEnabled(boolean) .
|
protected final void | enableEvents(long
the event mask defining the event types eventsToEnable)Enables event delivery to this menu item for events to be defined by the specified event mask parameter
Since event types are automatically enabled when a listener for
that type is added to the menu item, this method only needs
to be invoked by subclasses of |
pack-priv boolean | |
public AccessibleContext | Returns: an AccessibleAWTMenuItem that serves as the AccessibleContext of this MenuItemOverrides java. Implements javax. |
public String | Returns: the action command nameGets the command name of the action event that is fired by this menu item. |
pack-priv final String | |
public synchronized ActionListener[] | Returns: all of this menu item'sActionListener s
or an empty array if no action
listeners are currently registeredReturns an array of all the action listeners registered on this menu item. |
public String | Returns: the label of this menu item, ornull
if this menu item has no label.Gets the label for this menu item. |
public < the type of the listeners T extends EventListener> T[] | Returns: an array of all objects registered asFooListener s on this menu item,
or an empty array if no such
listeners have been addedthe type of listeners requested; this parameter
should specify an interface that descends from
listenerType)java.util.EventListener Returns an array of all the objects currently registered
as |
public MenuShortcut | Returns: the menu shortcut associated with this menu item, ornull if none has been specified.Get the |
pack-priv MenuItem | |
pack-priv boolean | |
private static native void | |
public boolean | Returns: true if the item is enabled;
otherwise false Checks whether this menu item is enabled. |
private boolean | |
public String | Returns: the parameter string of this menu itemOverrides java. MenuItem .
|
protected void | processActionEvent(ActionEvent
the action event e)Processes action events occurring on this menu item,
by dispatching them to any registered
|
protected void | processEvent(AWTEvent
the event e)Overrides java. |
private void | readObject(ObjectInputStream
the s)ObjectInputStream to readHides java. ObjectInputStream and if it
isn't null adds a listener to receive
action events fired by the Menu Item.
|
public synchronized void | removeActionListener(ActionListener
the action listener. l)Removes the specified action listener so it no longer receives action events from this menu item. |
public void | setActionCommand(String
the action command to be set
for this menu item. command)Sets the command name of the action event that is fired by this menu item. |
public synchronized void | setEnabled(boolean
if b)true , enables this menu item;
if false , disables it.Sets whether or not this menu item can be chosen. |
public synchronized void | |
public void | setShortcut(MenuShortcut
the menu shortcut to associate
with this menu item. s)Set the |
private void | writeObject(ObjectOutputStream
the s)ObjectOutputStream to writeWrites default serializable fields to stream. |
actionCommand | back to summary |
---|---|
private volatile String actionCommand This field indicates the command that has been issued
by a particular menu item.
By default the
|
actionListener | back to summary |
---|---|
private transient volatile ActionListener actionListener |
base | back to summary |
---|---|
private static final String base |
enabled | back to summary |
---|---|
private volatile boolean enabled A value to indicate whether a menu item is enabled
or not. If it is enabled,
|
eventMask | back to summary |
---|---|
pack-priv volatile long eventMask The eventMask is ONLY set by subclasses via enableEvents. The mask should NOT be set when listeners are registered so that we can distinguish the difference between when listeners request events and subclasses request them. |
label | back to summary |
---|---|
pack-priv volatile String label
|
menuItemSerializedDataVersion | back to summary |
---|---|
private int menuItemSerializedDataVersion Menu item serialized data version. |
nameCounter | back to summary |
---|---|
private static int nameCounter |
serialVersionUID | back to summary |
---|---|
private static final long serialVersionUID Hides java. Use serialVersionUID from JDK 1.1 for interoperability. |
shortcut | back to summary |
---|---|
private volatile MenuShortcut shortcut A sequence of key stokes that ia associated with a menu item. Note :in 1.1.2 you must use setActionCommand() on a menu item in order for its shortcut to work. |
MenuItem | back to summary |
---|---|
public MenuItem() throws HeadlessException Constructs a new MenuItem with an empty label and no keyboard shortcut.
|
MenuItem | back to summary |
---|---|
public MenuItem(String label) throws HeadlessException Constructs a new MenuItem with the specified label and no keyboard shortcut. Note that use of "-" in a label is reserved to indicate a separator between menu items. By default, all menu items except for separators are enabled.
|
MenuItem | back to summary |
---|---|
public MenuItem(String label, MenuShortcut s) throws HeadlessException Create a menu item with an associated keyboard shortcut. Note that use of "-" in a label is reserved to indicate a separator between menu items. By default, all menu items except for separators are enabled.
|
addActionListener | back to summary |
---|---|
public synchronized void addActionListener(ActionListener l) Adds the specified action listener to receive action events from this menu item. If l is null, no exception is thrown and no action is performed. Refer to AWT Threading Issues for details on AWT's threading model.
|
addNotify | back to summary |
---|---|
public void addNotify() Creates the menu item's peer. The peer allows us to modify the appearance of the menu item without changing its functionality. |
constructComponentName | back to summary |
---|---|
pack-priv String constructComponentName() Overrides java. Construct a name for this MenuComponent. Called by getName() when the name is null.
|
deleteShortcut | back to summary |
---|---|
public void deleteShortcut() Delete any
|
deleteShortcut | back to summary |
---|---|
pack-priv void deleteShortcut(MenuShortcut s) |
disable | back to summary |
---|---|
public synchronized void disable()
Deprecated As of JDK version 1.1,
replaced by
|
disableEvents | back to summary |
---|---|
protected final void disableEvents(long eventsToDisable) Disables event delivery to this menu item for events defined by the specified event mask parameter.
|
doMenuEvent | back to summary |
---|---|
pack-priv void doMenuEvent(long when, int modifiers) |
enable | back to summary |
---|---|
public synchronized void enable()
Deprecated As of JDK version 1.1,
replaced by
|
enable | back to summary |
---|---|
public void enable(boolean b)
Deprecated As of JDK version 1.1,
replaced by Sets whether or not this menu item can be chosen.
|
enableEvents | back to summary |
---|---|
protected final void enableEvents(long eventsToEnable) Enables event delivery to this menu item for events to be defined by the specified event mask parameter
Since event types are automatically enabled when a listener for
that type is added to the menu item, this method only needs
to be invoked by subclasses of
|
eventEnabled | back to summary |
---|---|
pack-priv boolean eventEnabled(AWTEvent e) Overrides java. |
getAccessibleContext | back to summary |
---|---|
public AccessibleContext getAccessibleContext() Overrides java. Implements javax. Gets the AccessibleContext associated with this MenuItem. For menu items, the AccessibleContext takes the form of an AccessibleAWTMenuItem. A new AccessibleAWTMenuItem instance is created if necessary.
|
getActionCommand | back to summary |
---|---|
public String getActionCommand() Gets the command name of the action event that is fired by this menu item.
|
getActionCommandImpl | back to summary |
---|---|
pack-priv final String getActionCommandImpl() |
getActionListeners | back to summary |
---|---|
public synchronized ActionListener[] getActionListeners() Returns an array of all the action listeners registered on this menu item.
|
getLabel | back to summary |
---|---|
public String getLabel() Gets the label for this menu item.
|
getListeners | back to summary |
---|---|
public <T extends EventListener> T[] getListeners(Class<T> listenerType) Returns an array of all the objects currently registered
as
You can specify the ActionListener[] als = (ActionListener[])(m.getListeners(ActionListener.class));If no such listeners exist, this method returns an empty array.
|
getShortcut | back to summary |
---|---|
public MenuShortcut getShortcut() Get the
|
getShortcutMenuItem | back to summary |
---|---|
pack-priv MenuItem getShortcutMenuItem(MenuShortcut s) |
handleShortcut | back to summary |
---|---|
pack-priv boolean handleShortcut(KeyEvent e)
|
initIDs | back to summary |
---|---|
private static native void initIDs() Initialize JNI field and method IDs |
isEnabled | back to summary |
---|---|
public boolean isEnabled() Checks whether this menu item is enabled.
|
isItemEnabled | back to summary |
---|---|
private boolean isItemEnabled() |
paramString | back to summary |
---|---|
public String paramString() Overrides java. Returns a string representing the state of this
|
processActionEvent | back to summary |
---|---|
protected void processActionEvent(ActionEvent e) Processes action events occurring on this menu item,
by dispatching them to any registered
Note that if the event parameter is
|
processEvent | back to summary |
---|---|
protected void processEvent(AWTEvent e) Overrides java. Processes events on this menu item. If the event is an
instance of Currently, menu items only support action events. Note that if the event parameter is
|
readObject | back to summary |
---|---|
private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException, HeadlessException Hides java. Reads the
|
removeActionListener | back to summary |
---|---|
public synchronized void removeActionListener(ActionListener l) Removes the specified action listener so it no longer receives action events from this menu item. If l is null, no exception is thrown and no action is performed. Refer to AWT Threading Issues for details on AWT's threading model.
|
setActionCommand | back to summary |
---|---|
public void setActionCommand(String command) Sets the command name of the action event that is fired by this menu item. By default, the action command is set to the label of the menu item.
|
setEnabled | back to summary |
---|---|
public synchronized void setEnabled(boolean b) Sets whether or not this menu item can be chosen.
|
setLabel | back to summary |
---|---|
public synchronized void setLabel(String label) Sets the label for this menu item to the specified label.
|
setShortcut | back to summary |
---|---|
public void setShortcut(MenuShortcut s) Set the
|
writeObject | back to summary |
---|---|
private void writeObject(ObjectOutputStream s) throws IOException Writes default serializable fields to stream. Writes
a list of serializable
|
This class implements accessibility support for the
MenuItem
class. It provides an implementation of the
Java Accessibility API appropriate to menu item user-interface elements.
Modifier and Type | Field and Description |
---|---|
private static final long | serialVersionUID
Hides java. |
Access | Constructor and Description |
---|---|
protected |
Modifier and Type | Method and Description |
---|---|
public boolean | Returns: true if the action was performed; otherwise false.zero-based index of actions i)Implements javax. |
public AccessibleAction | Returns: this objectOverrides javax. |
public int | Returns: 1, the number of Actions in this objectImplements javax. |
public String | getAccessibleActionDescription(int
zero-based index of the actions i)Implements javax. |
public String | Returns: the localized name of the object -- can be null if this object does not have a nameOverrides java. |
public AccessibleRole | Returns: an instance of AccessibleRole describing the role of the objectOverrides java. |
public AccessibleValue | Returns: this objectOverrides javax. |
public Number | Returns: An Integer of 0 if this isn't selected or an Integer of 1 if this is selected.Implements javax. |
public Number | Returns: An Integer of 0.Implements javax. |
public Number | Returns: An Integer of 0.Implements javax. |
public boolean | Returns: True if the value was set.the number to use for the value n)Implements javax. |
serialVersionUID | back to summary |
---|---|
private static final long serialVersionUID Hides java. Use serialVersionUID from JDK 1.3 for interoperability. |
AccessibleAWTMenuItem | back to summary |
---|---|
protected AccessibleAWTMenuItem() Constructs an |
doAccessibleAction | back to summary |
---|---|
public boolean doAccessibleAction(int i) Implements javax. Perform the specified Action on the object
|
getAccessibleAction | back to summary |
---|---|
public AccessibleAction getAccessibleAction() Overrides javax. Get the AccessibleAction associated with this object. In the implementation of the Java Accessibility API for this class, return this object, which is responsible for implementing the AccessibleAction interface on behalf of itself.
|
getAccessibleActionCount | back to summary |
---|---|
public int getAccessibleActionCount() Implements javax. Returns the number of Actions available in this object. The default behavior of a menu item is to have one action.
|
getAccessibleActionDescription | back to summary |
---|---|
public String getAccessibleActionDescription(int i) Implements javax. Return a description of the specified action of the object.
|
getAccessibleName | back to summary |
---|---|
public String getAccessibleName() Overrides java. Get the accessible name of this object.
|
getAccessibleRole | back to summary |
---|---|
public AccessibleRole getAccessibleRole() Overrides java. Get the role of this object.
|
getAccessibleValue | back to summary |
---|---|
public AccessibleValue getAccessibleValue() Overrides javax. Get the AccessibleValue associated with this object. In the implementation of the Java Accessibility API for this class, return this object, which is responsible for implementing the AccessibleValue interface on behalf of itself.
|
getCurrentAccessibleValue | back to summary |
---|---|
public Number getCurrentAccessibleValue() Implements javax. Get the value of this object as a Number.
|
getMaximumAccessibleValue | back to summary |
---|---|
public Number getMaximumAccessibleValue() Implements javax. Get the maximum value of this object as a Number.
|
getMinimumAccessibleValue | back to summary |
---|---|
public Number getMinimumAccessibleValue() Implements javax. Get the minimum value of this object as a Number.
|
setCurrentAccessibleValue | back to summary |
---|---|
public boolean setCurrentAccessibleValue(Number n) Implements javax. Set the value of this object as a Number.
|