JMenuItem
contained in a JPopupMenu
performs exactly that function.
Menu items can be configured, and to some degree controlled, by
Action
s. Using an
Action
with a menu item has many benefits beyond directly
configuring a menu item. Refer to
Swing Components Supporting Action
for more
details, and you can find more information in How
to Use Actions, a section in The Java Tutorial.
For further documentation and for examples, see How to Use Menus in The Java Tutorial.
Warning
Swing is not thread safe. For more information see Swing's Threading Policy.
Warning
Serialized objects of this class will not be compatible with
future Swing releases. The current serialization support is
appropriate for short term storage or RMI between applications running
the same version of Swing. As of 1.4, support for long term storage
of all JavaBeans
has been added to the java.beans
package.
Please see java.
.
JPopupMenu
, JMenu
, JCheckBoxMenuItem
, JRadioButtonMenuItem
Modifier and Type | Class and Description |
---|---|
protected class | JMenuItem.
This class implements accessibility support for the
|
private static class |
Modifier and Type | Field and Description |
---|---|
private KeyStroke | |
private static final boolean | |
private boolean | |
private static final boolean | |
private static final String | |
private static final boolean |
Access | Constructor and Description |
---|---|
public | |
public | |
public | |
public | |
public | |
public |
Modifier and Type | Method and Description |
---|---|
protected void | actionPropertyChanged(Action
the action, String Action associated with this buttonthe name of the property that changed propertyName)
Updates the button's state in response to property changes in the
associated action.
|
public void | addMenuDragMouseListener(MenuDragMouseListener
the l)MenuDragMouseListener to be addedAdds a |
public void | addMenuKeyListener(MenuKeyListener
the l)MenuKeyListener to be addedAdds a |
pack-priv boolean | alwaysOnTop()
Overrides javax. Menu s, by definition,
should always be on top of all other windows.
|
pack-priv void | |
protected void | configurePropertiesFromAction(Action
the a)Action from which to get the properties,
or null Overrides javax. Action .
|
protected void | fireMenuDragMouseDragged(MenuDragMouseEvent
a event)MenuDragMouseEvent Notifies all listeners that have registered interest for notification on this event type. |
protected void | fireMenuDragMouseEntered(MenuDragMouseEvent
a event)MenuMouseDragEvent Notifies all listeners that have registered interest for notification on this event type. |
protected void | fireMenuDragMouseExited(MenuDragMouseEvent
a event)MenuDragMouseEvent Notifies all listeners that have registered interest for notification on this event type. |
protected void | fireMenuDragMouseReleased(MenuDragMouseEvent
a event)MenuDragMouseEvent Notifies all listeners that have registered interest for notification on this event type. |
protected void | fireMenuKeyPressed(MenuKeyEvent
a event)MenuKeyEvent Notifies all listeners that have registered interest for notification on this event type. |
protected void | fireMenuKeyReleased(MenuKeyEvent
a event)MenuKeyEvent Notifies all listeners that have registered interest for notification on this event type. |
protected void | fireMenuKeyTyped(MenuKeyEvent
a event)MenuKeyEvent Notifies all listeners that have registered interest for notification on this event type. |
public KeyStroke | Returns: aKeyStroke object identifying the
accelerator keyReturns the |
public AccessibleContext | Returns: anAccessibleJMenuItem that serves as the
AccessibleContext of this JMenuItem Overrides java. Implements javax. AccessibleContext associated with this
JMenuItem .
|
public Component | Returns: theComponent that paints this menu itemImplements javax. java.awt.Component used to paint
this object.
|
public MenuDragMouseListener[] | Returns: all of theMenuDragMouseListener s added or an empty
array if no listeners have been addedReturns an array of all the |
public MenuKeyListener[] | Returns: all of theMenuKeyListener s added or an empty
array if no listeners have been addedReturns an array of all the |
public MenuElement[] | Returns: an array ofMenuElement sImplements javax. |
public String | Returns: the string "MenuItemUI"Overrides javax. |
protected void | init(String
the text of the text, Icon JMenuItem the icon of the icon)JMenuItem Overrides javax. |
pack-priv void | |
public boolean | Returns: true if the menu item is armed, and it can be selectedReturns whether the menu item is "armed". |
pack-priv void | |
public void | menuSelectionChanged(boolean
true if this menu item is on the part of the menu
path that changed, false if this menu is part of the
a menu path that changed, but this particular part of
that path is still the same isIncluded)Implements javax. MenuSelectionManager when the
MenuElement is selected or unselected.
|
protected String | Returns: a string representation of thisJMenuItem Overrides javax. JMenuItem .
|
public void | processKeyEvent(KeyEvent
a e, MenuElement[] KeyEvent the path, MenuSelectionManager MenuElement path arraythe manager)MenuSelectionManager Implements javax. MenuSelectionManager and changes the menu selection,
if necessary, by using MenuSelectionManager 's API.
|
public void | processMenuDragMouseEvent(MenuDragMouseEvent
a e)MenuDragMouseEvent objectHandles mouse drag in a menu. |
public void | |
public void | processMouseEvent(MouseEvent
a e, MenuElement[] MouseEvent the path, MenuSelectionManager MenuElement path arraythe manager)MenuSelectionManager Implements javax. MenuSelectionManager and changes the menu
selection, if necessary, by using the
MenuSelectionManager 's API.
|
private void | readObject(ObjectInputStream
the s)
See JComponent.readObject() for information about serialization
in Swing.
ObjectInputStream from which to read |
public void | removeMenuDragMouseListener(MenuDragMouseListener
the l)MenuDragMouseListener to be removedRemoves a |
public void | removeMenuKeyListener(MenuKeyListener
the l)MenuKeyListener to be removedRemoves a |
public void | setAccelerator(KeyStroke
the keyStroke)KeyStroke which will
serve as an acceleratorSets the key combination which invokes the menu item's action listeners without navigating the menu hierarchy. |
public void | setArmed(boolean
true to arm the menu item so it can be selected b)Identifies the menu item as "armed". |
public void | setEnabled(boolean
true to enable the item b)Overrides javax. |
pack-priv void | |
public void | setModel(ButtonModel
the new newModel)ButtonModel Overrides javax. |
public void | setUI(MenuItemUI
the ui)JMenuItemUI L&F objectSets the look and feel object that renders this component. |
pack-priv void | |
public void | updateUI()
Overrides javax. |
private void | writeObject(ObjectOutputStream
the s)ObjectOutputStream in which to writeHides javax. JComponent to an
ObjectOutputStream we temporarily uninstall its UI.
|
accelerator | back to summary |
---|---|
private KeyStroke accelerator |
DEBUG | back to summary |
---|---|
private static final boolean DEBUG |
isMouseDragged | back to summary |
---|---|
private boolean isMouseDragged |
TRACE | back to summary |
---|---|
private static final boolean TRACE |
uiClassID | back to summary |
---|---|
private static final String uiClassID Hides javax.
|
VERBOSE | back to summary |
---|---|
private static final boolean VERBOSE |
JMenuItem | back to summary |
---|---|
public JMenuItem() Creates a |
JMenuItem | back to summary |
---|---|
public JMenuItem(Icon icon) Creates a
|
JMenuItem | back to summary |
---|---|
public JMenuItem(String text) Creates a
|
JMenuItem | back to summary |
---|---|
public JMenuItem(Action a) Creates a menu item whose properties are taken from the
specified
|
JMenuItem | back to summary |
---|---|
public JMenuItem(String text, Icon icon) Creates a |
JMenuItem | back to summary |
---|---|
public JMenuItem(String text, int mnemonic) Creates a
|
actionPropertyChanged | back to summary |
---|---|
protected void actionPropertyChanged(Action action, String propertyName) Overrides javax. Doc from javax. Updates the button's state in response to property changes in the
associated action. This method is invoked from the
Refer to the table at
Swing Components Supporting |
addMenuDragMouseListener | back to summary |
---|---|
public void addMenuDragMouseListener(MenuDragMouseListener l) Adds a
|
addMenuKeyListener | back to summary |
---|---|
public void addMenuKeyListener(MenuKeyListener l) Adds a
|
alwaysOnTop | back to summary |
---|---|
pack-priv boolean alwaysOnTop() Overrides javax. Returns true since
|
configureAcceleratorFromAction | back to summary |
---|---|
pack-priv void configureAcceleratorFromAction(Action a) |
configurePropertiesFromAction | back to summary |
---|---|
protected void configurePropertiesFromAction(Action a) Overrides javax. Doc from javax. Sets the properties on this button to match those in the specified
|
fireMenuDragMouseDragged | back to summary |
---|---|
protected void fireMenuDragMouseDragged(MenuDragMouseEvent event) Notifies all listeners that have registered interest for notification on this event type.
|
fireMenuDragMouseEntered | back to summary |
---|---|
protected void fireMenuDragMouseEntered(MenuDragMouseEvent event) Notifies all listeners that have registered interest for notification on this event type.
|
fireMenuDragMouseExited | back to summary |
---|---|
protected void fireMenuDragMouseExited(MenuDragMouseEvent event) Notifies all listeners that have registered interest for notification on this event type.
|
fireMenuDragMouseReleased | back to summary |
---|---|
protected void fireMenuDragMouseReleased(MenuDragMouseEvent event) Notifies all listeners that have registered interest for notification on this event type.
|
fireMenuKeyPressed | back to summary |
---|---|
protected void fireMenuKeyPressed(MenuKeyEvent event) Notifies all listeners that have registered interest for notification on this event type.
|
fireMenuKeyReleased | back to summary |
---|---|
protected void fireMenuKeyReleased(MenuKeyEvent event) Notifies all listeners that have registered interest for notification on this event type.
|
fireMenuKeyTyped | back to summary |
---|---|
protected void fireMenuKeyTyped(MenuKeyEvent event) Notifies all listeners that have registered interest for notification on this event type.
|
getAccelerator | back to summary |
---|---|
public KeyStroke getAccelerator() Returns the
|
getAccessibleContext | back to summary |
---|---|
public AccessibleContext getAccessibleContext() Overrides java. Implements javax. Returns the
|
getComponent | back to summary |
---|---|
public Component getComponent() Implements javax. Returns the
|
getMenuDragMouseListeners | back to summary |
---|---|
public MenuDragMouseListener[] getMenuDragMouseListeners() Returns an array of all the
|
getMenuKeyListeners | back to summary |
---|---|
public MenuKeyListener[] getMenuKeyListeners() Returns an array of all the
|
getSubElements | back to summary |
---|---|
public MenuElement[] getSubElements() Implements javax. This method returns an array containing the sub-menu components for this menu component.
|
getUIClassID | back to summary |
---|---|
public String getUIClassID() Overrides javax. Returns the suffix used to construct the name of the L&F class used to render this component.
|
init | back to summary |
---|---|
protected void init(String text, Icon icon) Overrides javax. Initializes the menu item with the specified text and icon. |
initFocusability | back to summary |
---|---|
pack-priv void initFocusability() Initializes the focusability of the |
isArmed | back to summary |
---|---|
public boolean isArmed() Returns whether the menu item is "armed".
|
largeIconChanged | back to summary |
---|---|
pack-priv void largeIconChanged(Action a) Overrides javax. |
menuSelectionChanged | back to summary |
---|---|
public void menuSelectionChanged(boolean isIncluded) Implements javax. Called by the
|
paramString | back to summary |
---|---|
protected String paramString() Overrides javax. Returns a string representation of this
|
processKeyEvent | back to summary |
---|---|
public void processKeyEvent(KeyEvent e, MenuElement[] path, MenuSelectionManager manager) Implements javax. Processes a key event forwarded from the
Note you do not have to forward the event to sub-components.
This is done automatically by the
|
processMenuDragMouseEvent | back to summary |
---|---|
public void processMenuDragMouseEvent(MenuDragMouseEvent e) Handles mouse drag in a menu.
|
processMenuKeyEvent | back to summary |
---|---|
public void processMenuKeyEvent(MenuKeyEvent e) Handles a keystroke in a menu.
|
processMouseEvent | back to summary |
---|---|
public void processMouseEvent(MouseEvent e, MenuElement[] path, MenuSelectionManager manager) Implements javax. Processes a mouse event forwarded from the
Note you do not have to forward the event to sub-components.
This is done automatically by the
|
readObject | back to summary |
---|---|
private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException Hides javax. See JComponent.readObject() for information about serialization in Swing.
|
removeMenuDragMouseListener | back to summary |
---|---|
public void removeMenuDragMouseListener(MenuDragMouseListener l) Removes a
|
removeMenuKeyListener | back to summary |
---|---|
public void removeMenuKeyListener(MenuKeyListener l) Removes a
|
setAccelerator | back to summary |
---|---|
public void setAccelerator(KeyStroke keyStroke) Sets the key combination which invokes the menu item's action listeners without navigating the menu hierarchy. It is the UI's responsibility to install the correct action. Note that when the keyboard accelerator is typed, it will work whether or not the menu is currently displayed.
|
setArmed | back to summary |
---|---|
public void setArmed(boolean b) Identifies the menu item as "armed". If the mouse button is released while it is over this item, the menu's action event will fire. If the mouse button is released elsewhere, the event will not fire and the menu item will be disarmed.
|
setEnabled | back to summary |
---|---|
public void setEnabled(boolean b) Overrides javax. Enables or disables the menu item.
|
setIconFromAction | back to summary |
---|---|
pack-priv void setIconFromAction(Action a) Overrides javax. |
setModel | back to summary |
---|---|
public void setModel(ButtonModel newModel) Overrides javax. Doc from javax. Sets the model that this button represents.
|
setUI | back to summary |
---|---|
public void setUI(MenuItemUI ui) Sets the look and feel object that renders this component.
|
smallIconChanged | back to summary |
---|---|
pack-priv void smallIconChanged(Action a) Overrides javax. |
updateUI | back to summary |
---|---|
public void updateUI() Overrides javax. Resets the UI property with a value from the current look and feel.
|
writeObject | back to summary |
---|---|
private void writeObject(ObjectOutputStream s) throws IOException Hides javax. Doc from javax. Before writing a
|
JMenuItem
class. It provides an implementation of the
Java Accessibility API appropriate to menu item user-interface
elements.Warning
Serialized objects of this class will not be compatible with
future Swing releases. The current serialization support is
appropriate for short term storage or RMI between applications running
the same version of Swing. As of 1.4, support for long term storage
of all JavaBeans
has been added to the java.beans
package.
Please see java.
.
Modifier and Type | Field and Description |
---|---|
private boolean | |
private boolean | |
private boolean | |
private boolean |
Access | Constructor and Description |
---|---|
pack-priv |
Modifier and Type | Method and Description |
---|---|
private void | |
public AccessibleRole | Returns: an instance of AccessibleRole describing the role of the objectOverrides javax. |
public void | stateChanged(ChangeEvent
a ChangeEvent object e)Implements javax. |
hasFocus | back to summary |
---|---|
private boolean hasFocus |
isArmed | back to summary |
---|---|
private boolean isArmed |
isPressed | back to summary |
---|---|
private boolean isPressed |
isSelected | back to summary |
---|---|
private boolean isSelected |
AccessibleJMenuItem | back to summary |
---|---|
pack-priv AccessibleJMenuItem() |
fireAccessibilityFocusedEvent | back to summary |
---|---|
private void fireAccessibilityFocusedEvent(JMenuItem toCheck) |
getAccessibleRole | back to summary |
---|---|
public AccessibleRole getAccessibleRole() Overrides javax. Get the role of this object.
|
stateChanged | back to summary |
---|---|
public void stateChanged(ChangeEvent e) Implements javax. Supports the change listener interface and fires property changes.
|
Access | Constructor and Description |
---|---|
private |
Modifier and Type | Method and Description |
---|---|
public void | focusGained(FocusEvent
the event to be processed event)Implements java. |
public void | focusLost(FocusEvent
the event to be processed event)Implements java. |
MenuItemFocusListener | back to summary |
---|---|
private MenuItemFocusListener() |
focusGained | back to summary |
---|---|
public void focusGained(FocusEvent event) Implements java. Doc from java. Invoked when a component gains the keyboard focus.
|
focusLost | back to summary |
---|---|
public void focusLost(FocusEvent event) Implements java. Doc from java. Invoked when a component loses the keyboard focus.
|