java.lang.Object | ||
↳ | java.awt.MenuComponent | |
↳ | java.awt.MenuItem |
Known Direct Subclasses |
Known Indirect Subclasses |
All items in a menu must belong to the class
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.
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
MenuItem.AccessibleAWTMenuItem | Inner class of MenuItem used to provide default support for accessibility. |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Constructs a new MenuItem with an empty label and no keyboard
shortcut.
| |||||||||||
Constructs a new MenuItem with the specified label
and no keyboard shortcut.
| |||||||||||
Create a menu item with an associated keyboard shortcut.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Adds the specified action listener to receive action events
from this menu item.
| |||||||||||
Creates the menu item's peer.
| |||||||||||
Delete any
MenuShortcut object associated
with this menu item. | |||||||||||
This method is deprecated.
As of JDK version 1.1,
replaced by
setEnabled(boolean) .
| |||||||||||
This method is deprecated.
As of JDK version 1.1,
replaced by
setEnabled(boolean) .
| |||||||||||
This method is deprecated.
As of JDK version 1.1,
replaced by
setEnabled(boolean) .
| |||||||||||
Gets the AccessibleContext associated with this MenuItem.
| |||||||||||
Gets the command name of the action event that is fired
by this menu item.
| |||||||||||
Returns an array of all the action listeners
registered on this menu item.
| |||||||||||
Gets the label for this menu item.
| |||||||||||
Returns an array of all the objects currently registered
as
FooListener s
upon this MenuItem . | |||||||||||
Get the
MenuShortcut object associated with this
menu item, | |||||||||||
Checks whether this menu item is enabled.
| |||||||||||
Returns a string representing the state of this
MenuItem . | |||||||||||
Removes the specified action listener so it no longer receives
action events from this menu item.
| |||||||||||
Sets the command name of the action event that is fired
by this menu item.
| |||||||||||
Sets whether or not this menu item can be chosen.
| |||||||||||
Sets the label for this menu item to the specified label.
| |||||||||||
Set the
MenuShortcut object associated with this
menu item. |
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Disables event delivery to this menu item for events
defined by the specified event mask parameter.
| |||||||||||
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 | |||||||||||
Processes action events occurring on this menu item,
by dispatching them to any registered
ActionListener objects. | |||||||||||
Processes events on this menu item.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.awt.MenuComponent
| |||||||||||
From class
java.lang.Object
| |||||||||||
From interface
javax.accessibility.Accessible
|
Constructs a new MenuItem with an empty label and no keyboard shortcut.
HeadlessException | if GraphicsEnvironment.isHeadless() returns true. |
---|
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.
label | the label for this menu item. |
---|
HeadlessException | if GraphicsEnvironment.isHeadless() returns true. |
---|
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.
label | the label for this menu item. |
---|---|
s | the instance of MenuShortcut
associated with this menu item. |
HeadlessException | if GraphicsEnvironment.isHeadless() returns true. |
---|
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.
l | the action listener. |
---|
Creates the menu item's peer. The peer allows us to modify the appearance of the menu item without changing its functionality.
Delete any MenuShortcut
object associated
with this menu item.
This method is deprecated.
As of JDK version 1.1,
replaced by setEnabled(boolean)
.
This method is deprecated.
As of JDK version 1.1,
replaced by setEnabled(boolean)
.
This method is deprecated.
As of JDK version 1.1,
replaced by setEnabled(boolean)
.
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.
Gets the command name of the action event that is fired by this menu item.
Returns an array of all the action listeners registered on this menu item.
ActionListener
s
or an empty array if no action
listeners are currently registeredGets the label for this menu item.
null
if this menu item has no label.Returns an array of all the objects currently registered
as FooListener
s
upon this MenuItem
.
FooListener
s are registered using the
addFooListener
method.
You can specify the listenerType
argument
with a class literal, such as
FooListener.class
.
For example, you can query a
MenuItem
m
for its action listeners with the following code:
ActionListener[] als = (ActionListener[])(m.getListeners(ActionListener.class));If no such listeners exist, this method returns an empty array.
listenerType | the type of listeners requested; this parameter
should specify an interface that descends from
java.util.EventListener |
---|
FooListener
s on this menu item,
or an empty array if no such
listeners have been addedClassCastException | if listenerType
doesn't specify a class or interface that implements
java.util.EventListener |
---|
Get the MenuShortcut
object associated with this
menu item,
null
if none has been specified.Returns a string representing the state of this MenuItem
.
This method is intended to be used only for debugging purposes, and the
content and format of the returned string may vary between
implementations. The returned string may be empty but may not be
null
.
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.
l | the action listener. |
---|
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.
command | the action command to be set for this menu item. |
---|
Sets whether or not this menu item can be chosen.
b | if true , enables this menu item;
if false , disables it. |
---|
Sets the label for this menu item to the specified label.
label | the new label, or null for no label. |
---|
Set the MenuShortcut
object associated with this
menu item. If a menu shortcut is already associated with
this menu item, it is replaced.
s | the menu shortcut to associate with this menu item. |
---|
Disables event delivery to this menu item for events defined by the specified event mask parameter.
eventsToDisable | the event mask defining the event types |
---|
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 MenuItem
which desire to
have the specified event types delivered to processEvent
regardless of whether a listener is registered.
eventsToEnable | the event mask defining the event types |
---|
Processes action events occurring on this menu item,
by dispatching them to any registered
ActionListener
objects.
This method is not called unless action events are
enabled for this component. Action events are enabled
when one of the following occurs:
ActionListener
object is registered
via addActionListener
.
enableEvents
.
Note that if the event parameter is null
the behavior is unspecified and may result in an
exception.
e | the action event |
---|
Processes events on this menu item. If the event is an
instance of ActionEvent
, it invokes
processActionEvent
, another method
defined by MenuItem
.
Currently, menu items only support action events.
Note that if the event parameter is null
the behavior is unspecified and may result in an
exception.
e | the event |
---|