APIdia Launch Partner
Top Description Inners Fields Constructors Methods
java.awt

public Class CheckboxMenuItem

extends MenuItem
implements ItemSelectable, Accessible
Class Inheritance
All Implemented Interfaces
javax.accessibility.Accessible, java.awt.ItemSelectable
Imports
java.awt.event.ActionListener, .ItemEvent, .ItemListener, java.awt.peer.CheckboxMenuItemPeer, java.io.IOException, .ObjectInputStream, .ObjectOutputStream, .Serial, java.util.EventListener, javax.accessibility.Accessible, .AccessibleAction, .AccessibleContext, .AccessibleRole, .AccessibleValue, sun.awt.AWTAccessor

This class represents a check box that can be included in a menu. Selecting the check box in the menu changes its state from "on" to "off" or from "off" to "on."

The following picture depicts a menu which contains an instance of CheckBoxMenuItem:

Menu labeled Examples, containing items Basic, Simple, Check, and More
Examples. The Check item is a CheckBoxMenuItem instance, in the off state.

The item labeled Check shows a check box menu item in its "off" state.

When a check box menu item is selected, AWT sends an item event to the item. Since the event is an instance of ItemEvent, the processEvent method examines the event and passes it along to processItemEvent. The latter method redirects the event to any ItemListener objects that have registered an interest in item events generated by this menu item.

Author
Sami Shaio
Since
1.0
See Also
java.awt.event.ItemEvent, java.awt.event.ItemListener

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected class
CheckboxMenuItem.AccessibleAWTCheckboxMenuItem

Inner class of CheckboxMenuItem used to provide default support for accessibility.

Field Summary

Modifier and TypeField and Description
private static final String
private int
checkboxMenuItemSerializedDataVersion

Serialized data version.

private transient volatile ItemListener
private static int
private static final long
serialVersionUID

Hides java.awt.MenuItem.serialVersionUID.

Use serialVersionUID from JDK 1.1 for interoperability.
private volatile boolean
state

The state of a checkbox menu item

Inherited from java.awt.MenuItem:
eventMasklabel

Constructor Summary

AccessConstructor and Description
public
CheckboxMenuItem()

Create a check box menu item with an empty label.

public
CheckboxMenuItem(String
a string label for the check box menu item, or null for an unlabeled menu item.
label
)

Create a check box menu item with the specified label.

public
CheckboxMenuItem(String
a string label for the check box menu item, or null for an unlabeled menu item.
label
,
boolean
the initial state of the menu item, where true indicates "on" and false indicates "off."
state
)

Create a check box menu item with the specified label and state.

Method Summary

Modifier and TypeMethod and Description
public synchronized void
addItemListener(ItemListener
the item listener
l
)

Implements java.awt.ItemSelectable.addItemListener.

Adds the specified item listener to receive item events from this check box menu item.

public void
addNotify()

Overrides java.awt.MenuItem.addNotify.

Creates the peer of the checkbox item.

pack-priv String
constructComponentName()

Overrides java.awt.MenuItem.constructComponentName.

Construct a name for this MenuComponent.

pack-priv void
doMenuEvent(long when, int modifiers)

Overrides java.awt.MenuItem.doMenuEvent.

pack-priv boolean
public AccessibleContext

Returns:

an AccessibleAWTCheckboxMenuItem that serves as the AccessibleContext of this CheckboxMenuItem
getAccessibleContext
()

Overrides java.awt.MenuItem.getAccessibleContext.

Implements javax.accessibility.Accessible.getAccessibleContext.

Gets the AccessibleContext associated with this CheckboxMenuItem.

public synchronized ItemListener[]

Returns:

all of this checkbox menuitem's ItemListeners or an empty array if no item listeners are currently registered
getItemListeners
()

Returns an array of all the item listeners registered on this checkbox menuitem.

public <T extends EventListener> T[]

Returns:

an array of all objects registered as FooListeners on this checkbox menuitem, or an empty array if no such listeners have been added
getListeners
(Class<T>
the type of listeners requested; this parameter should specify an interface that descends from java.util.EventListener
listenerType
)

Overrides java.awt.MenuItem.getListeners.

Returns an array of all the objects currently registered as FooListeners upon this CheckboxMenuItem.

public synchronized Object[]
getSelectedObjects()

Implements java.awt.ItemSelectable.getSelectedObjects.

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

public boolean

Returns:

the state of this check box menu item, where true indicates "on" and false indicates "off"
getState
()

Determines whether the state of this check box menu item is "on" or "off."

private static native void
initIDs()

Hides java.awt.MenuItem.initIDs.

Initialize JNI field and method IDs

public String

Returns:

the parameter string of this check box menu item
paramString
()

Overrides java.awt.MenuItem.paramString.

Returns a string representing the state of this CheckBoxMenuItem.

protected void
processEvent(AWTEvent
the event
e
)

Overrides java.awt.MenuItem.processEvent.

Processes events on this check box menu item.

protected void
processItemEvent(ItemEvent
the item event
e
)

Processes item events occurring on this check box menu item by dispatching them to any registered ItemListener objects.

private void
readObject(ObjectInputStream
the ObjectInputStream to read
s
)

Hides java.awt.MenuItem.readObject.

Reads the ObjectInputStream and if it isn't null adds a listener to receive item events fired by the Checkbox menu item.

public synchronized void
removeItemListener(ItemListener
the item listener
l
)

Implements java.awt.ItemSelectable.removeItemListener.

Removes the specified item listener so that it no longer receives item events from this check box menu item.

public synchronized void
setState(boolean
true if the check box menu item is on, otherwise false
b
)

Sets this check box menu item to the specified state.

private void
writeObject(ObjectOutputStream
the ObjectOutputStream to write
s
)

Hides java.awt.MenuItem.writeObject.

Writes default serializable fields to stream.

Inherited from java.awt.MenuItem:
addActionListenerdeleteShortcutdeleteShortcutdisabledisableEventsenableenableenableEventsgetActionCommandgetActionCommandImplgetActionListenersgetLabelgetShortcutgetShortcutMenuItemhandleShortcutisEnabledprocessActionEventremoveActionListenersetActionCommandsetEnabledsetLabelsetShortcut

Field Detail

baseback to summary
private static final String base

Hides java.awt.MenuItem.base.

checkboxMenuItemSerializedDataVersionback to summary
private int checkboxMenuItemSerializedDataVersion

Serialized data version.

itemListenerback to summary
private transient volatile ItemListener itemListener
nameCounterback to summary
private static int nameCounter

Hides java.awt.MenuItem.nameCounter.

serialVersionUIDback to summary
private static final long serialVersionUID

Hides java.awt.MenuItem.serialVersionUID.

Use serialVersionUID from JDK 1.1 for interoperability.

Annotations
@Serial
stateback to summary
private volatile boolean state

The state of a checkbox menu item

See Also
getState(), setState(boolean)

Constructor Detail

CheckboxMenuItemback to summary
public CheckboxMenuItem() throws HeadlessException

Create a check box menu item with an empty label. The item's state is initially set to "off."

Exceptions
HeadlessException:
if GraphicsEnvironment.isHeadless() returns true
Since
1.1
See Also
java.awt.GraphicsEnvironment#isHeadless
CheckboxMenuItemback to summary
public CheckboxMenuItem(String label) throws HeadlessException

Create a check box menu item with the specified label. The item's state is initially set to "off."

Parameters
label:String

a string label for the check box menu item, or null for an unlabeled menu item.

Exceptions
HeadlessException:
if GraphicsEnvironment.isHeadless() returns true
See Also
java.awt.GraphicsEnvironment#isHeadless
CheckboxMenuItemback to summary
public CheckboxMenuItem(String label, boolean state) throws HeadlessException

Create a check box menu item with the specified label and state.

Parameters
label:String

a string label for the check box menu item, or null for an unlabeled menu item.

state:boolean

the initial state of the menu item, where true indicates "on" and false indicates "off."

Exceptions
HeadlessException:
if GraphicsEnvironment.isHeadless() returns true
Since
1.1
See Also
java.awt.GraphicsEnvironment#isHeadless

Method Detail

addItemListenerback to summary
public synchronized void addItemListener(ItemListener l)

Implements java.awt.ItemSelectable.addItemListener.

Adds the specified item listener to receive item events from this check box menu item. Item events are sent in response to user actions, but not in response to calls to setState(). 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.

Parameters
l:ItemListener

the item listener

Since
1.1
See Also
removeItemListener, getItemListeners, setState, java.awt.event.ItemEvent, java.awt.event.ItemListener
addNotifyback to summary
public void addNotify()

Overrides java.awt.MenuItem.addNotify.

Creates the peer of the checkbox item. This peer allows us to change the look of the checkbox item without changing its functionality. Most applications do not call this method directly.

See Also
java.awt.Component#getToolkit()
constructComponentNameback to summary
pack-priv String constructComponentName()

Overrides java.awt.MenuItem.constructComponentName.

Construct a name for this MenuComponent. Called by getName() when the name is null.

doMenuEventback to summary
pack-priv void doMenuEvent(long when, int modifiers)

Overrides java.awt.MenuItem.doMenuEvent.

eventEnabledback to summary
pack-priv boolean eventEnabled(AWTEvent e)

Overrides java.awt.MenuItem.eventEnabled.

getAccessibleContextback to summary
public AccessibleContext getAccessibleContext()

Overrides java.awt.MenuItem.getAccessibleContext.

Implements javax.accessibility.Accessible.getAccessibleContext.

Gets the AccessibleContext associated with this CheckboxMenuItem. For checkbox menu items, the AccessibleContext takes the form of an AccessibleAWTCheckboxMenuItem. A new AccessibleAWTCheckboxMenuItem is created if necessary.

Returns:AccessibleContext

an AccessibleAWTCheckboxMenuItem that serves as the AccessibleContext of this CheckboxMenuItem

Since
1.3
getItemListenersback to summary
public synchronized ItemListener[] getItemListeners()

Returns an array of all the item listeners registered on this checkbox menuitem.

Returns:ItemListener[]

all of this checkbox menuitem's ItemListeners or an empty array if no item listeners are currently registered

Since
1.4
See Also
addItemListener, removeItemListener, java.awt.event.ItemEvent, java.awt.event.ItemListener
getListenersback to summary
public <T extends EventListener> T[] getListeners(Class<T> listenerType)

Overrides java.awt.MenuItem.getListeners.

Returns an array of all the objects currently registered as FooListeners upon this CheckboxMenuItem. FooListeners 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 CheckboxMenuItem c for its item listeners with the following code:

ItemListener[] ils = (ItemListener[])(c.getListeners(ItemListener.class));
If no such listeners exist, this method returns an empty array.
Parameters
listenerType:Class<T>

the type of listeners requested; this parameter should specify an interface that descends from java.util.EventListener

Returns:T[]

an array of all objects registered as FooListeners on this checkbox menuitem, or an empty array if no such listeners have been added

Exceptions
ClassCastException:
if listenerType doesn't specify a class or interface that implements java.util.EventListener
Since
1.3
See Also
getItemListeners
getSelectedObjectsback to summary
public synchronized Object[] getSelectedObjects()

Implements java.awt.ItemSelectable.getSelectedObjects.

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

See Also
ItemSelectable
getStateback to summary
public boolean getState()

Determines whether the state of this check box menu item is "on" or "off."

Returns:boolean

the state of this check box menu item, where true indicates "on" and false indicates "off"

See Also
setState
initIDsback to summary
private static native void initIDs()

Hides java.awt.MenuItem.initIDs.

Initialize JNI field and method IDs

paramStringback to summary
public String paramString()

Overrides java.awt.MenuItem.paramString.

Returns a string representing the state of this CheckBoxMenuItem. 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

the parameter string of this check box menu item

processEventback to summary
protected void processEvent(AWTEvent e)

Overrides java.awt.MenuItem.processEvent.

Processes events on this check box menu item. If the event is an instance of ItemEvent, this method invokes the processItemEvent method. If the event is not an item event, it invokes processEvent on the superclass.

Check box menu items currently support only item events.

Note that if the event parameter is null the behavior is unspecified and may result in an exception.

Parameters
e:AWTEvent

the event

Since
1.1
See Also
java.awt.event.ItemEvent, processItemEvent
processItemEventback to summary
protected void processItemEvent(ItemEvent e)

Processes item events occurring on this check box menu item by dispatching them to any registered ItemListener objects.

This method is not called unless item events are enabled for this menu item. Item events are enabled when one of the following occurs:

  • An ItemListener object is registered via addItemListener.
  • Item events are enabled via enableEvents.

Note that if the event parameter is null the behavior is unspecified and may result in an exception.

Parameters
e:ItemEvent

the item event

Since
1.1
See Also
java.awt.event.ItemEvent, java.awt.event.ItemListener, addItemListener, java.awt.MenuItem#enableEvents
readObjectback to summary
private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException

Hides java.awt.MenuItem.readObject.

Reads the ObjectInputStream and if it isn't null adds a listener to receive item events fired by the Checkbox menu item. Unrecognized keys or values will be ignored.

Parameters
s:ObjectInputStream

the ObjectInputStream to read

Annotations
@Serial
Exceptions
ClassNotFoundException:
if the class of a serialized object could not be found
IOException:
if an I/O error occurs
See Also
removeActionListener(ActionListener), addActionListener(ActionListener), writeObject(ObjectOutputStream)
removeItemListenerback to summary
public synchronized void removeItemListener(ItemListener l)

Implements java.awt.ItemSelectable.removeItemListener.

Removes the specified item listener so that it no longer receives item events from this check box 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.

Parameters
l:ItemListener

the item listener

Since
1.1
See Also
addItemListener, getItemListeners, java.awt.event.ItemEvent, java.awt.event.ItemListener
setStateback to summary
public synchronized void setState(boolean b)

Sets this check box menu item to the specified state. The boolean value true indicates "on" while false indicates "off."

Note that this method should be primarily used to initialize the state of the check box menu item. Programmatically setting the state of the check box menu item will not trigger an ItemEvent. The only way to trigger an ItemEvent is by user interaction.

Parameters
b:boolean

true if the check box menu item is on, otherwise false

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

Hides java.awt.MenuItem.writeObject.

Writes default serializable fields to stream. Writes a list of serializable ItemListeners as optional data. The non-serializable ItemListeners are detected and no attempt is made to serialize them.

Parameters
s:ObjectOutputStream

the ObjectOutputStream to write

Annotations
@Serial
Exceptions
IOException:
if an I/O error occurs
Serial data
null terminated sequence of 0 or more pairs; the pair consists of a String and an Object; the String indicates the type of object and is one of the following: itemListenerK indicating an ItemListener object
See Also
AWTEventMulticaster#save(ObjectOutputStream, String, EventListener), java.awt.Component#itemListenerK, readObject(ObjectInputStream)
java.awt back to summary

protected Class CheckboxMenuItem.AccessibleAWTCheckboxMenuItem

extends AccessibleAWTMenuItem
implements AccessibleAction, AccessibleValue
Class Inheritance
All Implemented Interfaces
javax.accessibility.AccessibleValue, javax.accessibility.AccessibleAction

Inner class of CheckboxMenuItem used to provide default support for accessibility. This class is not meant to be used directly by application developers, but is instead meant only to be subclassed by menu component developers.

This class implements accessibility support for the CheckboxMenuItem class. It provides an implementation of the Java Accessibility API appropriate to checkbox menu item user-interface elements.

Since
1.3

Field Summary

Modifier and TypeField and Description
private static final long
serialVersionUID

Hides java.awt.MenuItem.AccessibleAWTMenuItem.serialVersionUID.

Use serialVersionUID from JDK 1.3 for interoperability.

Constructor Summary

AccessConstructor and Description
protected
AccessibleAWTCheckboxMenuItem()

Constructs an AccessibleAWTCheckboxMenuItem.

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if the action was performed; otherwise false.
doAccessibleAction
(int
zero-based index of actions
i
)

Overrides java.awt.MenuItem.AccessibleAWTMenuItem.doAccessibleAction.

Implements javax.accessibility.AccessibleAction.doAccessibleAction.

Perform the specified Action on the object

public AccessibleAction

Returns:

this object
getAccessibleAction
()

Overrides java.awt.MenuItem.AccessibleAWTMenuItem.getAccessibleAction.

Get the AccessibleAction associated with this object.

public int

Returns:

the number of Actions in this object
getAccessibleActionCount
()

Overrides java.awt.MenuItem.AccessibleAWTMenuItem.getAccessibleActionCount.

Implements javax.accessibility.AccessibleAction.getAccessibleActionCount.

Returns the number of Actions available in this object.

public String
getAccessibleActionDescription(int
zero-based index of the actions
i
)

Overrides java.awt.MenuItem.AccessibleAWTMenuItem.getAccessibleActionDescription.

Implements javax.accessibility.AccessibleAction.getAccessibleActionDescription.

Return a description of the specified action of the object.

public AccessibleRole

Returns:

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

Overrides java.awt.MenuItem.AccessibleAWTMenuItem.getAccessibleRole.

Get the role of this object.

public AccessibleValue

Returns:

this object
getAccessibleValue
()

Overrides java.awt.MenuItem.AccessibleAWTMenuItem.getAccessibleValue.

Get the AccessibleValue associated with this object.

public Number
public Number

Returns:

Maximum value of the object; null if this object does not have a maximum value
getMaximumAccessibleValue
()

Overrides java.awt.MenuItem.AccessibleAWTMenuItem.getMaximumAccessibleValue.

Implements javax.accessibility.AccessibleValue.getMaximumAccessibleValue.

Get the maximum value of this object as a Number.

public Number

Returns:

Minimum value of the object; null if this object does not have a minimum value
getMinimumAccessibleValue
()

Overrides java.awt.MenuItem.AccessibleAWTMenuItem.getMinimumAccessibleValue.

Implements javax.accessibility.AccessibleValue.getMinimumAccessibleValue.

Get the minimum value of this object as a Number.

public boolean

Returns:

true if the value was set; otherwise false
setCurrentAccessibleValue
(Number n)

Overrides java.awt.MenuItem.AccessibleAWTMenuItem.setCurrentAccessibleValue.

Implements javax.accessibility.AccessibleValue.setCurrentAccessibleValue.

Set the value of this object as a Number.

Inherited from java.awt.MenuItem.AccessibleAWTMenuItem:
getAccessibleName

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Hides java.awt.MenuItem.AccessibleAWTMenuItem.serialVersionUID.

Use serialVersionUID from JDK 1.3 for interoperability.

Annotations
@Serial

Constructor Detail

AccessibleAWTCheckboxMenuItemback to summary
protected AccessibleAWTCheckboxMenuItem()

Constructs an AccessibleAWTCheckboxMenuItem.

Method Detail

doAccessibleActionback to summary
public boolean doAccessibleAction(int i)

Overrides java.awt.MenuItem.AccessibleAWTMenuItem.doAccessibleAction.

Implements javax.accessibility.AccessibleAction.doAccessibleAction.

Perform the specified Action on the object

Parameters
i:int

zero-based index of actions

Returns:boolean

true if the action was performed; otherwise false.

getAccessibleActionback to summary
public AccessibleAction getAccessibleAction()

Overrides java.awt.MenuItem.AccessibleAWTMenuItem.getAccessibleAction.

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.

Returns:AccessibleAction

this object

getAccessibleActionCountback to summary
public int getAccessibleActionCount()

Overrides java.awt.MenuItem.AccessibleAWTMenuItem.getAccessibleActionCount.

Implements javax.accessibility.AccessibleAction.getAccessibleActionCount.

Returns the number of Actions available in this object. If there is more than one, the first one is the "default" action.

Returns:int

the number of Actions in this object

getAccessibleActionDescriptionback to summary
public String getAccessibleActionDescription(int i)

Overrides java.awt.MenuItem.AccessibleAWTMenuItem.getAccessibleActionDescription.

Implements javax.accessibility.AccessibleAction.getAccessibleActionDescription.

Return a description of the specified action of the object.

Parameters
i:int

zero-based index of the actions

getAccessibleRoleback to summary
public AccessibleRole getAccessibleRole()

Overrides java.awt.MenuItem.AccessibleAWTMenuItem.getAccessibleRole.

Get the role of this object.

Returns:AccessibleRole

an instance of AccessibleRole describing the role of the object

getAccessibleValueback to summary
public AccessibleValue getAccessibleValue()

Overrides java.awt.MenuItem.AccessibleAWTMenuItem.getAccessibleValue.

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.

Returns:AccessibleValue

this object

getCurrentAccessibleValueback to summary
public Number getCurrentAccessibleValue()

Overrides java.awt.MenuItem.AccessibleAWTMenuItem.getCurrentAccessibleValue.

Implements javax.accessibility.AccessibleValue.getCurrentAccessibleValue.

Get the value of this object as a Number. If the value has not been set, the return value will be null.

Returns:Number

value of the object

See Also
setCurrentAccessibleValue
getMaximumAccessibleValueback to summary
public Number getMaximumAccessibleValue()

Overrides java.awt.MenuItem.AccessibleAWTMenuItem.getMaximumAccessibleValue.

Implements javax.accessibility.AccessibleValue.getMaximumAccessibleValue.

Get the maximum value of this object as a Number.

Returns:Number

Maximum value of the object; null if this object does not have a maximum value

See Also
getMinimumAccessibleValue
getMinimumAccessibleValueback to summary
public Number getMinimumAccessibleValue()

Overrides java.awt.MenuItem.AccessibleAWTMenuItem.getMinimumAccessibleValue.

Implements javax.accessibility.AccessibleValue.getMinimumAccessibleValue.

Get the minimum value of this object as a Number.

Returns:Number

Minimum value of the object; null if this object does not have a minimum value

See Also
getMaximumAccessibleValue
setCurrentAccessibleValueback to summary
public boolean setCurrentAccessibleValue(Number n)

Overrides java.awt.MenuItem.AccessibleAWTMenuItem.setCurrentAccessibleValue.

Implements javax.accessibility.AccessibleValue.setCurrentAccessibleValue.

Set the value of this object as a Number.

Returns:boolean

true if the value was set; otherwise false

See Also
getCurrentAccessibleValue