Top Description Inners Fields Constructors Methods
javax.swing

public Class JCheckBoxMenuItem

extends JMenuItem
implements SwingConstants, Accessible
Class Inheritance
All Implemented Interfaces
javax.accessibility.Accessible, javax.swing.SwingConstants
Annotations
@JavaBean
description:A menu item which can be selected or deselected.
@SwingContainer:false
@SuppressWarnings:serial
Imports
java.beans.BeanProperty, .JavaBean, java.io.IOException, .ObjectOutputStream, .Serial, javax.accessibility.Accessible, .AccessibleContext, .AccessibleRole

A menu item that can be selected or deselected. If selected, the menu item typically appears with a checkmark next to it. If unselected or deselected, the menu item appears without a checkmark. Like a regular menu item, a check box menu item can have either text or a graphic icon associated with it, or both.

Either isSelected/setSelected or getState/setState can be used to determine/specify the menu item's selection state. The preferred methods are isSelected and setSelected, which work for all menus and buttons. The getState and setState methods exist for compatibility with other component sets.

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.

Some times it is required to select several check box menu items from a menu. In this case it is useful that clicking on one check box menu item does not close the menu. Such behavior can be controlled either by client JComponent#putClientProperty or the Look and Feel UIManager#put property named "CheckBoxMenuItem.doNotCloseOnMouseClick". The default value is false. Setting the property to true prevents the menu from closing when it is clicked by the mouse. If the client property is set its value is always used; otherwise the L&F property is queried.

Note

some L&Fs may ignore this property. All built-in L&Fs inherit this behaviour.

For further information and examples of using check box menu items, see How to Use Menus, a section 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

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected class
JCheckBoxMenuItem.AccessibleJCheckBoxMenuItem

This class implements accessibility support for the JCheckBoxMenuItem class.

Field Summary

Modifier and TypeField and Description
private static final String

Constructor Summary

AccessConstructor and Description
public
JCheckBoxMenuItem()

Creates an initially unselected check box menu item with no set text or icon.

public
JCheckBoxMenuItem(Icon
the icon of the JCheckBoxMenuItem.
icon
)

Creates an initially unselected check box menu item with an icon.

public
JCheckBoxMenuItem(String
the text of the JCheckBoxMenuItem
text
)

Creates an initially unselected check box menu item with text.

public
JCheckBoxMenuItem(Action
the action of the JCheckBoxMenuItem
a
)

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

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

Creates an initially unselected check box menu item with the specified text and icon.

public
JCheckBoxMenuItem(String
the text of the check box menu item.
text
,
boolean
the selected state of the check box menu item
b
)

Creates a check box menu item with the specified text and selection state.

public
JCheckBoxMenuItem(String
the text of the check box menu item
text
,
Icon
the icon of the check box menu item
icon
,
boolean
the selected state of the check box menu item
b
)

Creates a check box menu item with the specified text, icon, and selection state.

Method Summary

Modifier and TypeMethod and Description
public AccessibleContext

Returns:

an AccessibleJCheckBoxMenuItem that serves as the AccessibleContext of this AccessibleJCheckBoxMenuItem
getAccessibleContext
()

Overrides javax.swing.JMenuItem.getAccessibleContext.

Implements javax.accessibility.Accessible.getAccessibleContext.

Gets the AccessibleContext associated with this JCheckBoxMenuItem.
public Object[]

Returns:

an array containing one Object -- the text of the menu item -- if the item is selected; otherwise null
getSelectedObjects
()

Overrides javax.swing.AbstractButton.getSelectedObjects.

Implements java.awt.ItemSelectable.getSelectedObjects.

Returns an array (length 1) containing the check box menu item label or null if the check box is not selected.
public boolean

Returns:

true if the item is selected
getState
()

Returns the selected-state of the item.

public String

Returns:

the string "CheckBoxMenuItemUI"
getUIClassID
()

Overrides javax.swing.JMenuItem.getUIClassID.

Returns the name of the L&F class that renders this component.
protected String

Returns:

a string representation of this JCheckBoxMenuItem.
paramString
()

Overrides javax.swing.JMenuItem.paramString.

Returns a string representation of this JCheckBoxMenuItem.
public synchronized void
setState(boolean
a boolean value indicating the item's selected-state, where true=selected
b
)

Sets the selected-state of the item.

pack-priv boolean
shouldUpdateSelectedStateFromAction()

Overrides javax.swing.AbstractButton.shouldUpdateSelectedStateFromAction.

Overridden to return true, JCheckBoxMenuItem supports the selected state.
private void
writeObject(ObjectOutputStream
the ObjectOutputStream in which to write
s
)

Hides javax.swing.JMenuItem.writeObject.

See readObject() and writeObject() in JComponent for more information about serialization in Swing.
Inherited from javax.swing.JMenuItem:
actionPropertyChangedaddMenuDragMouseListeneraddMenuKeyListeneralwaysOnTopconfigureAcceleratorFromActionconfigurePropertiesFromActionfireMenuDragMouseDraggedfireMenuDragMouseEnteredfireMenuDragMouseExitedfireMenuDragMouseReleasedfireMenuKeyPressedfireMenuKeyReleasedfireMenuKeyTypedgetAcceleratorgetComponentgetMenuDragMouseListenersgetMenuKeyListenersgetSubElementsinitinitFocusabilityisArmedlargeIconChangedmenuSelectionChangedprocessKeyEventprocessMenuDragMouseEventprocessMenuKeyEventprocessMouseEventremoveMenuDragMouseListenerremoveMenuKeyListenersetAcceleratorsetArmedsetEnabledsetIconFromActionsetModelsetUIsmallIconChangedupdateUI

Field Detail

uiClassIDback to summary
private static final String uiClassID

Hides javax.swing.JMenuItem.uiClassID.

See Also
getUIClassID, readObject

Constructor Detail

JCheckBoxMenuItemback to summary
public JCheckBoxMenuItem()

Creates an initially unselected check box menu item with no set text or icon.

JCheckBoxMenuItemback to summary
public JCheckBoxMenuItem(Icon icon)

Creates an initially unselected check box menu item with an icon.

Parameters
icon:Icon

the icon of the JCheckBoxMenuItem.

JCheckBoxMenuItemback to summary
public JCheckBoxMenuItem(String text)

Creates an initially unselected check box menu item with text.

Parameters
text:String

the text of the JCheckBoxMenuItem

JCheckBoxMenuItemback to summary
public JCheckBoxMenuItem(Action a)

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

Parameters
a:Action

the action of the JCheckBoxMenuItem

Since
1.3
JCheckBoxMenuItemback to summary
public JCheckBoxMenuItem(String text, Icon icon)

Creates an initially unselected check box menu item with the specified text and icon.

Parameters
text:String

the text of the JCheckBoxMenuItem

icon:Icon

the icon of the JCheckBoxMenuItem

JCheckBoxMenuItemback to summary
public JCheckBoxMenuItem(String text, boolean b)

Creates a check box menu item with the specified text and selection state.

Parameters
text:String

the text of the check box menu item.

b:boolean

the selected state of the check box menu item

JCheckBoxMenuItemback to summary
public JCheckBoxMenuItem(String text, Icon icon, boolean b)

Creates a check box menu item with the specified text, icon, and selection state.

Parameters
text:String

the text of the check box menu item

icon:Icon

the icon of the check box menu item

b:boolean

the selected state of the check box menu item

Method Detail

getAccessibleContextback to summary
public AccessibleContext getAccessibleContext()

Overrides javax.swing.JMenuItem.getAccessibleContext.

Implements javax.accessibility.Accessible.getAccessibleContext.

Gets the AccessibleContext associated with this JCheckBoxMenuItem. For JCheckBoxMenuItems, the AccessibleContext takes the form of an AccessibleJCheckBoxMenuItem. A new AccessibleJCheckBoxMenuItem instance is created if necessary.

Returns:AccessibleContext

an AccessibleJCheckBoxMenuItem that serves as the AccessibleContext of this AccessibleJCheckBoxMenuItem

Annotations
@BeanProperty
bound:false
getSelectedObjectsback to summary
public Object[] getSelectedObjects()

Overrides javax.swing.AbstractButton.getSelectedObjects.

Implements java.awt.ItemSelectable.getSelectedObjects.

Returns an array (length 1) containing the check box menu item label or null if the check box is not selected.

Returns:Object[]

an array containing one Object -- the text of the menu item -- if the item is selected; otherwise null

Annotations
@BeanProperty
bound:false
getStateback to summary
public boolean getState()

Returns the selected-state of the item. This method exists for AWT compatibility only. New code should use isSelected() instead.

Returns:boolean

true if the item is selected

getUIClassIDback to summary
public String getUIClassID()

Overrides javax.swing.JMenuItem.getUIClassID.

Returns the name of the L&F class that renders this component.

Returns:String

the string "CheckBoxMenuItemUI"

Annotations
@BeanProperty
bound:false
See Also
JComponent#getUIClassID, UIDefaults#getUI
paramStringback to summary
protected String paramString()

Overrides javax.swing.JMenuItem.paramString.

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

setStateback to summary
public synchronized void setState(boolean b)

Sets the selected-state of the item. This method exists for AWT compatibility only. New code should use setSelected() instead.

Parameters
b:boolean

a boolean value indicating the item's selected-state, where true=selected

Annotations
@BeanProperty
bound:false
hidden:true
description:The selection state of the check box menu item
shouldUpdateSelectedStateFromActionback to summary
pack-priv boolean shouldUpdateSelectedStateFromAction()

Overrides javax.swing.AbstractButton.shouldUpdateSelectedStateFromAction.

Overridden to return true, JCheckBoxMenuItem supports the selected state.

writeObjectback to summary
private void writeObject(ObjectOutputStream s) throws IOException

Hides javax.swing.JMenuItem.writeObject.

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

Parameters
s:ObjectOutputStream

Doc from javax.swing.JComponent.writeObject.

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 JCheckBoxMenuItem.AccessibleJCheckBoxMenuItem

extends AccessibleJMenuItem
Class Inheritance
Annotations
@SuppressWarnings:serial

This class implements accessibility support for the JCheckBoxMenuItem class. It provides an implementation of the Java Accessibility API appropriate to checkbox 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.

Constructor Summary

AccessConstructor and Description
protected
AccessibleJCheckBoxMenuItem()

Constructs an AccessibleJCheckBoxMenuItem.

Method Summary

Modifier and TypeMethod and Description
public AccessibleRole

Returns:

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

Overrides javax.swing.JMenuItem.AccessibleJMenuItem.getAccessibleRole.

Get the role of this object.
Inherited from javax.swing.JMenuItem.AccessibleJMenuItem:
stateChanged

Constructor Detail

AccessibleJCheckBoxMenuItemback to summary
protected AccessibleJCheckBoxMenuItem()

Constructs an AccessibleJCheckBoxMenuItem.

Method Detail

getAccessibleRoleback to summary
public AccessibleRole getAccessibleRole()

Overrides javax.swing.JMenuItem.AccessibleJMenuItem.getAccessibleRole.

Get the role of this object.

Returns:AccessibleRole

an instance of AccessibleRole describing the role of the object