Top Description Inners Fields Constructors Methods
javax.swing

public Class JMenuItem

extends AbstractButton
implements Accessible, MenuElement
Class Inheritance
All Implemented Interfaces
javax.swing.MenuElement, javax.accessibility.Accessible
Known Direct Subclasses
javax.swing.JRadioButtonMenuItem, javax.swing.JCheckBoxMenuItem, javax.swing.JMenu
Annotations
@JavaBean
defaultProperty:UIClassID
description:An item which can be selected in a menu.
@SwingContainer:false
@SuppressWarnings:serial
Imports
java.awt.Component, java.awt.event.FocusEvent, .FocusListener, .KeyEvent, .MouseEvent, java.beans.BeanProperty, .JavaBean, java.io.IOException, .ObjectInputStream, .ObjectOutputStream, .Serial, .Serializable, javax.accessibility.Accessible, .AccessibleContext, .AccessibleRole, .AccessibleState, javax.swing.event.ChangeEvent, .ChangeListener, .EventListenerList, .MenuDragMouseEvent, .MenuDragMouseListener, .MenuKeyEvent, .MenuKeyListener, javax.swing.plaf.MenuItemUI

An implementation of an item in a menu. A menu item is essentially a button sitting in a list. When the user selects the "button", the action associated with the menu item is performed. A JMenuItem contained in a JPopupMenu performs exactly that function.

Menu items can be configured, and to some degree controlled, by Actions. 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.beans.XMLEncoder.

Authors
Georges Saab, David Karlton
Since
1.2
See Also
JPopupMenu, JMenu, JCheckBoxMenuItem, JRadioButtonMenuItem

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected class
JMenuItem.AccessibleJMenuItem

This class implements accessibility support for the JMenuItem class.

Field Summary

Modifier and TypeField and Description
private KeyStroke
private static final boolean
private boolean
private static final boolean
private static final String
private static final boolean
Inherited from javax.swing.AbstractButton:
actionListenerBORDER_PAINTED_CHANGED_PROPERTYchangeEventchangeListenerCONTENT_AREA_FILLED_CHANGED_PROPERTYdefaultCapableDISABLED_ICON_CHANGED_PROPERTYDISABLED_SELECTED_ICON_CHANGED_PROPERTYFOCUS_PAINTED_CHANGED_PROPERTYHORIZONTAL_ALIGNMENT_CHANGED_PROPERTYHORIZONTAL_TEXT_POSITION_CHANGED_PROPERTYICON_CHANGED_PROPERTYitemListenerMARGIN_CHANGED_PROPERTYMNEMONIC_CHANGED_PROPERTYmodelMODEL_CHANGED_PROPERTYPRESSED_ICON_CHANGED_PROPERTYROLLOVER_ENABLED_CHANGED_PROPERTYROLLOVER_ICON_CHANGED_PROPERTYROLLOVER_SELECTED_ICON_CHANGED_PROPERTYSELECTED_ICON_CHANGED_PROPERTYTEXT_CHANGED_PROPERTYVERTICAL_ALIGNMENT_CHANGED_PROPERTYVERTICAL_TEXT_POSITION_CHANGED_PROPERTY

Constructor Summary

AccessConstructor and Description
public
JMenuItem()

Creates a JMenuItem with no set text or icon.

public
JMenuItem(Icon
the icon of the JMenuItem
icon
)

Creates a JMenuItem with the specified icon.

public
JMenuItem(String
the text of the JMenuItem
text
)

Creates a JMenuItem with the specified text.

public
JMenuItem(Action
the action of the JMenuItem
a
)

Creates a menu item whose properties are taken from the specified Action.

public
JMenuItem(String
the text of the JMenuItem
text
,
Icon
the icon of the JMenuItem
icon
)

Creates a JMenuItem with the specified text and icon.

public
JMenuItem(String
the text of the JMenuItem
text
,
int
the keyboard mnemonic for the JMenuItem
mnemonic
)

Creates a JMenuItem with the specified text and keyboard mnemonic.

Method Summary

Modifier and TypeMethod and Description
protected void
actionPropertyChanged(Action
the Action associated with this button
action
,
String
the name of the property that changed
propertyName
)

Overrides javax.swing.AbstractButton.actionPropertyChanged.

Updates the button's state in response to property changes in the associated action.
public void
addMenuDragMouseListener(MenuDragMouseListener
the MenuDragMouseListener to be added
l
)

Adds a MenuDragMouseListener to the menu item.

public void
addMenuKeyListener(MenuKeyListener
the MenuKeyListener to be added
l
)

Adds a MenuKeyListener to the menu item.

pack-priv boolean
alwaysOnTop()

Overrides javax.swing.JComponent.alwaysOnTop.

Returns true since Menus, by definition, should always be on top of all other windows.
pack-priv void
protected void
configurePropertiesFromAction(Action
the Action from which to get the properties, or null
a
)

Overrides javax.swing.AbstractButton.configurePropertiesFromAction.

Sets the properties on this button to match those in the specified Action.
protected void
fireMenuDragMouseDragged(MenuDragMouseEvent
a MenuDragMouseEvent
event
)

Notifies all listeners that have registered interest for notification on this event type.

protected void
fireMenuDragMouseEntered(MenuDragMouseEvent
a MenuMouseDragEvent
event
)

Notifies all listeners that have registered interest for notification on this event type.

protected void
fireMenuDragMouseExited(MenuDragMouseEvent
a MenuDragMouseEvent
event
)

Notifies all listeners that have registered interest for notification on this event type.

protected void
fireMenuDragMouseReleased(MenuDragMouseEvent
a MenuDragMouseEvent
event
)

Notifies all listeners that have registered interest for notification on this event type.

protected void
fireMenuKeyPressed(MenuKeyEvent
a MenuKeyEvent
event
)

Notifies all listeners that have registered interest for notification on this event type.

protected void
fireMenuKeyReleased(MenuKeyEvent
a MenuKeyEvent
event
)

Notifies all listeners that have registered interest for notification on this event type.

protected void
fireMenuKeyTyped(MenuKeyEvent
a MenuKeyEvent
event
)

Notifies all listeners that have registered interest for notification on this event type.

public KeyStroke

Returns:

a KeyStroke object identifying the accelerator key
getAccelerator
()

Returns the KeyStroke which serves as an accelerator for the menu item.

public AccessibleContext

Returns:

an AccessibleJMenuItem that serves as the AccessibleContext of this JMenuItem
getAccessibleContext
()

Overrides java.awt.Component.getAccessibleContext.

Implements javax.accessibility.Accessible.getAccessibleContext.

Returns the AccessibleContext associated with this JMenuItem.
public Component

Returns:

the Component that paints this menu item
getComponent
()

Implements javax.swing.MenuElement.getComponent.

Returns the java.awt.Component used to paint this object.
public MenuDragMouseListener[]

Returns:

all of the MenuDragMouseListeners added or an empty array if no listeners have been added
getMenuDragMouseListeners
()

Returns an array of all the MenuDragMouseListeners added to this JMenuItem with addMenuDragMouseListener().

public MenuKeyListener[]

Returns:

all of the MenuKeyListeners added or an empty array if no listeners have been added
getMenuKeyListeners
()

Returns an array of all the MenuKeyListeners added to this JMenuItem with addMenuKeyListener().

public MenuElement[]

Returns:

an array of MenuElements
getSubElements
()

Implements javax.swing.MenuElement.getSubElements.

This method returns an array containing the sub-menu components for this menu component.
public String

Returns:

the string "MenuItemUI"
getUIClassID
()

Overrides javax.swing.JComponent.getUIClassID.

Returns the suffix used to construct the name of the L&F class used to render this component.
protected void
init(String
the text of the JMenuItem
text
,
Icon
the icon of the JMenuItem
icon
)

Overrides javax.swing.AbstractButton.init.

Initializes the menu item with the specified text and icon.
pack-priv void
initFocusability()

Initializes the focusability of the JMenuItem.

public boolean

Returns:

true if the menu item is armed, and it can be selected
isArmed
()

Returns whether the menu item is "armed".

pack-priv void
protected String

Returns:

a string representation of this JMenuItem
paramString
()

Overrides javax.swing.AbstractButton.paramString.

Returns a string representation of this JMenuItem.
public void
processKeyEvent(KeyEvent
a KeyEvent
e
,
MenuElement[]
the MenuElement path array
path
,
MenuSelectionManager
the MenuSelectionManager
manager
)

Implements javax.swing.MenuElement.processKeyEvent.

Processes a key event forwarded from the MenuSelectionManager and changes the menu selection, if necessary, by using MenuSelectionManager's API.
public void
processMenuDragMouseEvent(MenuDragMouseEvent
a MenuDragMouseEvent object
e
)

Handles mouse drag in a menu.

public void
processMenuKeyEvent(MenuKeyEvent
a MenuKeyEvent object
e
)

Handles a keystroke in a menu.

public void
processMouseEvent(MouseEvent
a MouseEvent
e
,
MenuElement[]
the MenuElement path array
path
,
MenuSelectionManager
the MenuSelectionManager
manager
)

Implements javax.swing.MenuElement.processMouseEvent.

Processes a mouse event forwarded from the MenuSelectionManager and changes the menu selection, if necessary, by using the MenuSelectionManager's API.
private void
readObject(ObjectInputStream
the ObjectInputStream from which to read
s
)

Hides javax.swing.JComponent.readObject.

See JComponent.readObject() for information about serialization in Swing.
public void
removeMenuDragMouseListener(MenuDragMouseListener
the MenuDragMouseListener to be removed
l
)

Removes a MenuDragMouseListener from the menu item.

public void
removeMenuKeyListener(MenuKeyListener
the MenuKeyListener to be removed
l
)

Removes a MenuKeyListener from the menu item.

public void
setAccelerator(KeyStroke
the KeyStroke which will serve as an accelerator
keyStroke
)

Sets 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.swing.AbstractButton.setEnabled.

Enables or disables the menu item.
pack-priv void
public void
setModel(ButtonModel
the new ButtonModel
newModel
)

Overrides javax.swing.AbstractButton.setModel.

Sets the model that this button represents.
public void
setUI(MenuItemUI
the JMenuItemUI L&F object
ui
)

Sets the look and feel object that renders this component.

pack-priv void
public void
updateUI()

Overrides javax.swing.AbstractButton.updateUI.

Resets the UI property with a value from the current look and feel.
private void
writeObject(ObjectOutputStream
the ObjectOutputStream in which to write
s
)

Hides javax.swing.JComponent.writeObject.

Before writing a JComponent to an ObjectOutputStream we temporarily uninstall its UI.
Inherited from javax.swing.AbstractButton:
addActionListeneraddChangeListeneraddImpladdItemListenercheckHorizontalKeycheckVerticalKeyclientPropertyChangedcreateActionListenercreateActionPropertyChangeListenercreateActionPropertyChangeListener0createChangeListenercreateItemListenerdoClickdoClickfireActionPerformedfireItemStateChangedfireStateChangedgetActiongetActionCommandgetActionListenersgetChangeListenersgetDisabledIcongetDisabledSelectedIcongetDisplayedMnemonicIndexgetHideActionTextgetHorizontalAlignmentgetHorizontalTextPositiongetIcongetIconTextGapgetItemListenersgetLabelgetMargingetMnemonicgetModelgetMultiClickThreshholdgetPressedIcongetRolloverIcongetRolloverSelectedIcongetSelectedIcongetSelectedObjectsgetTextgetUIgetVerticalAlignmentgetVerticalTextPositionimageUpdateisBorderPaintedisContentAreaFilledisFocusPaintedisRolloverEnabledisSelectedpaintBorderremoveActionListenerremoveChangeListenerremoveItemListenerremoveNotifysetActionsetActionCommandsetBorderPaintedsetContentAreaFilledsetDisabledIconsetDisabledSelectedIconsetDisplayedMnemonicIndexsetFocusPaintedsetHideActionTextsetHorizontalAlignmentsetHorizontalTextPositionsetIconsetIconTextGapsetLabelsetLayoutsetMarginsetMnemonicsetMnemonicsetMultiClickThreshholdsetPressedIconsetRolloverEnabledsetRolloverIconsetRolloverSelectedIconsetSelectedsetSelectedIconsetTextsetUIsetUIPropertysetVerticalAlignmentsetVerticalTextPositionshouldUpdateSelectedStateFromAction

Field Detail

acceleratorback to summary
private KeyStroke accelerator
DEBUGback to summary
private static final boolean DEBUG
isMouseDraggedback to summary
private boolean isMouseDragged
TRACEback to summary
private static final boolean TRACE
uiClassIDback to summary
private static final String uiClassID

Hides javax.swing.JComponent.uiClassID.

See Also
getUIClassID, readObject
VERBOSEback to summary
private static final boolean VERBOSE

Constructor Detail

JMenuItemback to summary
public JMenuItem()

Creates a JMenuItem with no set text or icon.

JMenuItemback to summary
public JMenuItem(Icon icon)

Creates a JMenuItem with the specified icon.

Parameters
icon:Icon

the icon of the JMenuItem

JMenuItemback to summary
public JMenuItem(String text)

Creates a JMenuItem with the specified text.

Parameters
text:String

the text of the JMenuItem

JMenuItemback to summary
public JMenuItem(Action a)

Creates a menu item whose properties are taken from the specified Action.

Parameters
a:Action

the action of the JMenuItem

Since
1.3
JMenuItemback to summary
public JMenuItem(String text, Icon icon)

Creates a JMenuItem with the specified text and icon.

Parameters
text:String

the text of the JMenuItem

icon:Icon

the icon of the JMenuItem

JMenuItemback to summary
public JMenuItem(String text, int mnemonic)

Creates a JMenuItem with the specified text and keyboard mnemonic.

Parameters
text:String

the text of the JMenuItem

mnemonic:int

the keyboard mnemonic for the JMenuItem

Method Detail

actionPropertyChangedback to summary
protected void actionPropertyChanged(Action action, String propertyName)

Overrides javax.swing.AbstractButton.actionPropertyChanged.

Doc from javax.swing.AbstractButton.actionPropertyChanged.

Updates the button's state in response to property changes in the associated action. This method is invoked from the PropertyChangeListener returned from createActionPropertyChangeListener. Subclasses do not normally need to invoke this. Subclasses that support additional Action properties should override this and configurePropertiesFromAction.

Refer to the table at Swing Components Supporting Action for a list of the properties this method sets.

Parameters
action:Action

the Action associated with this button

propertyName:String

the name of the property that changed

Since
1.6
addMenuDragMouseListenerback to summary
public void addMenuDragMouseListener(MenuDragMouseListener l)

Adds a MenuDragMouseListener to the menu item.

Parameters
l:MenuDragMouseListener

the MenuDragMouseListener to be added

addMenuKeyListenerback to summary
public void addMenuKeyListener(MenuKeyListener l)

Adds a MenuKeyListener to the menu item.

Parameters
l:MenuKeyListener

the MenuKeyListener to be added

alwaysOnTopback to summary
pack-priv boolean alwaysOnTop()

Overrides javax.swing.JComponent.alwaysOnTop.

Returns true since Menus, by definition, should always be on top of all other windows. If the menu is in an internal frame false is returned due to the rollover effect for windows laf where the menu is not always on top.

Returns:boolean

Doc from javax.swing.JComponent.alwaysOnTop.

always returns false

configureAcceleratorFromActionback to summary
pack-priv void configureAcceleratorFromAction(Action a)
configurePropertiesFromActionback to summary
protected void configurePropertiesFromAction(Action a)

Overrides javax.swing.AbstractButton.configurePropertiesFromAction.

Doc from javax.swing.AbstractButton.configurePropertiesFromAction.

Sets the properties on this button to match those in the specified Action. Refer to Swing Components Supporting Action for more details as to which properties this sets.

Parameters
a:Action

the Action from which to get the properties, or null

Since
1.3
fireMenuDragMouseDraggedback to summary
protected void fireMenuDragMouseDragged(MenuDragMouseEvent event)

Notifies all listeners that have registered interest for notification on this event type.

Parameters
event:MenuDragMouseEvent

a MenuDragMouseEvent

See Also
EventListenerList
fireMenuDragMouseEnteredback to summary
protected void fireMenuDragMouseEntered(MenuDragMouseEvent event)

Notifies all listeners that have registered interest for notification on this event type.

Parameters
event:MenuDragMouseEvent

a MenuMouseDragEvent

See Also
EventListenerList
fireMenuDragMouseExitedback to summary
protected void fireMenuDragMouseExited(MenuDragMouseEvent event)

Notifies all listeners that have registered interest for notification on this event type.

Parameters
event:MenuDragMouseEvent

a MenuDragMouseEvent

See Also
EventListenerList
fireMenuDragMouseReleasedback to summary
protected void fireMenuDragMouseReleased(MenuDragMouseEvent event)

Notifies all listeners that have registered interest for notification on this event type.

Parameters
event:MenuDragMouseEvent

a MenuDragMouseEvent

See Also
EventListenerList
fireMenuKeyPressedback to summary
protected void fireMenuKeyPressed(MenuKeyEvent event)

Notifies all listeners that have registered interest for notification on this event type.

Parameters
event:MenuKeyEvent

a MenuKeyEvent

See Also
EventListenerList
fireMenuKeyReleasedback to summary
protected void fireMenuKeyReleased(MenuKeyEvent event)

Notifies all listeners that have registered interest for notification on this event type.

Parameters
event:MenuKeyEvent

a MenuKeyEvent

See Also
EventListenerList
fireMenuKeyTypedback to summary
protected void fireMenuKeyTyped(MenuKeyEvent event)

Notifies all listeners that have registered interest for notification on this event type.

Parameters
event:MenuKeyEvent

a MenuKeyEvent

See Also
EventListenerList
getAcceleratorback to summary
public KeyStroke getAccelerator()

Returns the KeyStroke which serves as an accelerator for the menu item.

Returns:KeyStroke

a KeyStroke object identifying the accelerator key

getAccessibleContextback to summary
public AccessibleContext getAccessibleContext()

Overrides java.awt.Component.getAccessibleContext.

Implements javax.accessibility.Accessible.getAccessibleContext.

Returns the AccessibleContext associated with this JMenuItem. For JMenuItems, the AccessibleContext takes the form of an AccessibleJMenuItem. A new AccessibleJMenuItem instance is created if necessary.

Returns:AccessibleContext

an AccessibleJMenuItem that serves as the AccessibleContext of this JMenuItem

Annotations
@BeanProperty
bound:false
getComponentback to summary
public Component getComponent()

Implements javax.swing.MenuElement.getComponent.

Returns the java.awt.Component used to paint this object. The returned component will be used to convert events and detect if an event is inside a menu component.

Returns:Component

the Component that paints this menu item

getMenuDragMouseListenersback to summary
public MenuDragMouseListener[] getMenuDragMouseListeners()

Returns an array of all the MenuDragMouseListeners added to this JMenuItem with addMenuDragMouseListener().

Returns:MenuDragMouseListener[]

all of the MenuDragMouseListeners added or an empty array if no listeners have been added

Annotations
@BeanProperty
bound:false
Since
1.4
getMenuKeyListenersback to summary
public MenuKeyListener[] getMenuKeyListeners()

Returns an array of all the MenuKeyListeners added to this JMenuItem with addMenuKeyListener().

Returns:MenuKeyListener[]

all of the MenuKeyListeners added or an empty array if no listeners have been added

Annotations
@BeanProperty
bound:false
Since
1.4
getSubElementsback to summary
public MenuElement[] getSubElements()

Implements javax.swing.MenuElement.getSubElements.

This method returns an array containing the sub-menu components for this menu component.

Returns:MenuElement[]

an array of MenuElements

Annotations
@BeanProperty
bound:false
getUIClassIDback to summary
public String getUIClassID()

Overrides javax.swing.JComponent.getUIClassID.

Returns the suffix used to construct the name of the L&F class used to render this component.

Returns:String

the string "MenuItemUI"

Annotations
@BeanProperty
bound:false
See Also
JComponent#getUIClassID, UIDefaults#getUI
initback to summary
protected void init(String text, Icon icon)

Overrides javax.swing.AbstractButton.init.

Initializes the menu item with the specified text and icon.

Parameters
text:String

the text of the JMenuItem

icon:Icon

the icon of the JMenuItem

initFocusabilityback to summary
pack-priv void initFocusability()

Initializes the focusability of the JMenuItem. JMenuItem's are non-focusable, but subclasses may want to be, this provides them the opportunity to override this and invoke something else, or nothing at all. Refer to javax.swing.JMenu#initFocusability for the motivation of this.

isArmedback to summary
public boolean isArmed()

Returns whether the menu item is "armed".

Returns:boolean

true if the menu item is armed, and it can be selected

See Also
setArmed
largeIconChangedback to summary
pack-priv void largeIconChanged(Action a)

Overrides javax.swing.AbstractButton.largeIconChanged.

paramStringback to summary
protected String paramString()

Overrides javax.swing.AbstractButton.paramString.

Returns a string representation of this JMenuItem. 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.

Returns:String

a string representation of this JMenuItem

processKeyEventback to summary
public void processKeyEvent(KeyEvent e, MenuElement[] path, MenuSelectionManager manager)

Implements javax.swing.MenuElement.processKeyEvent.

Processes a key event forwarded from the MenuSelectionManager and changes the menu selection, if necessary, by using MenuSelectionManager's API.

Note

you do not have to forward the event to sub-components. This is done automatically by the MenuSelectionManager.

Parameters
e:KeyEvent

a KeyEvent

path:MenuElement[]

the MenuElement path array

manager:MenuSelectionManager

the MenuSelectionManager

Annotations
@SuppressWarnings:deprecation
processMenuDragMouseEventback to summary
public void processMenuDragMouseEvent(MenuDragMouseEvent e)

Handles mouse drag in a menu.

Parameters
e:MenuDragMouseEvent

a MenuDragMouseEvent object

processMenuKeyEventback to summary
public void processMenuKeyEvent(MenuKeyEvent e)

Handles a keystroke in a menu.

Parameters
e:MenuKeyEvent

a MenuKeyEvent object

processMouseEventback to summary
public void processMouseEvent(MouseEvent e, MenuElement[] path, MenuSelectionManager manager)

Implements javax.swing.MenuElement.processMouseEvent.

Processes a mouse event forwarded from the MenuSelectionManager and changes the menu selection, if necessary, by using the MenuSelectionManager's API.

Note

you do not have to forward the event to sub-components. This is done automatically by the MenuSelectionManager.

Parameters
e:MouseEvent

a MouseEvent

path:MenuElement[]

the MenuElement path array

manager:MenuSelectionManager

the MenuSelectionManager

Annotations
@SuppressWarnings:deprecation
readObjectback to summary
private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException

Hides javax.swing.JComponent.readObject.

See JComponent.readObject() for information about serialization in Swing.

Parameters
s:ObjectInputStream

Doc from javax.swing.JComponent.readObject.

the ObjectInputStream from which to read

Annotations
@Serial
Exceptions
IOException:

Doc from java.awt.Container.readObject.

if an I/O error occurs

ClassNotFoundException:

Doc from java.awt.Container.readObject.

if the class of a serialized object could not be found

removeMenuDragMouseListenerback to summary
public void removeMenuDragMouseListener(MenuDragMouseListener l)

Removes a MenuDragMouseListener from the menu item.

Parameters
l:MenuDragMouseListener

the MenuDragMouseListener to be removed

removeMenuKeyListenerback to summary
public void removeMenuKeyListener(MenuKeyListener l)

Removes a MenuKeyListener from the menu item.

Parameters
l:MenuKeyListener

the MenuKeyListener to be removed

setAcceleratorback 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.

Parameters
keyStroke:KeyStroke

the KeyStroke which will serve as an accelerator

Annotations
@BeanProperty
preferred:true
description:The keystroke combination which will invoke the JMenuItem\'s actionlisteners without navigating the menu hierarchy
setArmedback 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.

Parameters
b:boolean

true to arm the menu item so it can be selected

Annotations
@BeanProperty
bound:false
hidden:true
description:Mouse release will fire an action event
setEnabledback to summary
public void setEnabled(boolean b)

Overrides javax.swing.AbstractButton.setEnabled.

Enables or disables the menu item.

Parameters
b:boolean

true to enable the item

Annotations
@BeanProperty
preferred:true
description:The enabled state of the component.
setIconFromActionback to summary
pack-priv void setIconFromAction(Action a)

Overrides javax.swing.AbstractButton.setIconFromAction.

setModelback to summary
public void setModel(ButtonModel newModel)

Overrides javax.swing.AbstractButton.setModel.

Doc from javax.swing.AbstractButton.setModel.

Sets the model that this button represents.

Parameters
newModel:ButtonModel

the new ButtonModel

setUIback to summary
public void setUI(MenuItemUI ui)

Sets the look and feel object that renders this component.

Parameters
ui:MenuItemUI

the JMenuItemUI L&F object

Annotations
@BeanProperty
hidden:true
visualUpdate:true
description:The UI object that implements the LookAndFeel.
See Also
UIDefaults#getUI
smallIconChangedback to summary
pack-priv void smallIconChanged(Action a)

Overrides javax.swing.AbstractButton.smallIconChanged.

updateUIback to summary
public void updateUI()

Overrides javax.swing.AbstractButton.updateUI.

Resets the UI property with a value from the current look and feel.

See Also
JComponent#updateUI
writeObjectback to summary
private void writeObject(ObjectOutputStream s) throws IOException

Hides javax.swing.JComponent.writeObject.

Doc from javax.swing.JComponent.writeObject.

Before writing a JComponent to an ObjectOutputStream we temporarily uninstall its UI. This is tricky to do because we want to uninstall the UI before any of the JComponent's children (or its LayoutManager etc.) are written, and we don't want to restore the UI until the most derived JComponent subclass has been stored.

Parameters
s:ObjectOutputStream

the ObjectOutputStream in which to write

Annotations
@Serial
Exceptions
IOException:

Doc from java.awt.Container.writeObject.

if an I/O error occurs

javax.swing back to summary

protected Class JMenuItem.AccessibleJMenuItem

extends AccessibleAbstractButton
implements ChangeListener
Class Inheritance
All Implemented Interfaces
javax.swing.event.ChangeListener, java.util.EventListener
Known Direct Subclasses
javax.swing.JRadioButtonMenuItem.AccessibleJRadioButtonMenuItem, javax.swing.JCheckBoxMenuItem.AccessibleJCheckBoxMenuItem, javax.swing.JMenu.AccessibleJMenu
Annotations
@SuppressWarnings:serial

This class implements accessibility support for the 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.beans.XMLEncoder.

Field Summary

Modifier and TypeField and Description
private boolean
private boolean
private boolean
private boolean

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
private void
public AccessibleRole

Returns:

an instance of AccessibleRole describing the role of the object
getAccessibleRole
()

Overrides javax.swing.JComponent.AccessibleJComponent.getAccessibleRole.

Get the role of this object.
public void
stateChanged(ChangeEvent
a ChangeEvent object
e
)

Implements javax.swing.event.ChangeListener.stateChanged.

Supports the change listener interface and fires property changes.
Inherited from javax.swing.AbstractButton.AccessibleAbstractButton:
doAccessibleActiongetAccessibleActiongetAccessibleActionCountgetAccessibleActionDescriptiongetAccessibleExtendedComponentgetAccessibleIcongetAccessibleKeyBindinggetAccessibleNamegetAccessibleRelationSetgetAccessibleStateSetgetAccessibleTextgetAccessibleValuegetAfterIndexgetAtIndexgetBeforeIndexgetCaretPositiongetCharacterAttributegetCharacterBoundsgetCharCountgetCurrentAccessibleValuegetIndexAtPointgetMaximumAccessibleValuegetMinimumAccessibleValuegetSelectedTextgetSelectionEndgetSelectionStartgetTitledBorderTextgetToolTipTextsetCurrentAccessibleValue

Field Detail

hasFocusback to summary
private boolean hasFocus
isArmedback to summary
private boolean isArmed
isPressedback to summary
private boolean isPressed
isSelectedback to summary
private boolean isSelected

Constructor Detail

AccessibleJMenuItemback to summary
pack-priv AccessibleJMenuItem()

Method Detail

fireAccessibilityFocusedEventback to summary
private void fireAccessibilityFocusedEvent(JMenuItem toCheck)
getAccessibleRoleback to summary
public AccessibleRole getAccessibleRole()

Overrides javax.swing.JComponent.AccessibleJComponent.getAccessibleRole.

Get the role of this object.

Returns:AccessibleRole

an instance of AccessibleRole describing the role of the object

stateChangedback to summary
public void stateChanged(ChangeEvent e)

Implements javax.swing.event.ChangeListener.stateChanged.

Supports the change listener interface and fires property changes.

Parameters
e:ChangeEvent

Doc from javax.swing.event.ChangeListener.stateChanged.

a ChangeEvent object