- All Implemented Interfaces:
- ItemSelectable,- Serializable,- Accessible
 The following picture depicts a menu which contains an instance
 of CheckBoxMenuItem:
 
  
 
 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.
- Since:
- 1.0
- See Also:
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionprotected classInner class of CheckboxMenuItem used to provide default support for accessibility.Nested classes/interfaces declared in class java.awt.MenuItemMenuItem.AccessibleAWTMenuItemNested classes/interfaces declared in class java.awt.MenuComponentMenuComponent.AccessibleAWTMenuComponent
- 
Constructor SummaryConstructorsConstructorDescriptionCreate a check box menu item with an empty label.CheckboxMenuItem(String label) Create a check box menu item with the specified label.CheckboxMenuItem(String label, boolean state) Create a check box menu item with the specified label and state.
- 
Method SummaryModifier and TypeMethodDescriptionvoidAdds the specified item listener to receive item events from this check box menu item.voidCreates the peer of the checkbox item.Gets the AccessibleContext associated with this CheckboxMenuItem.Returns an array of all the item listeners registered on this checkbox menuitem.<T extends EventListener>
 T[]getListeners(Class<T> listenerType) Returns an array of all the objects currently registered asFooListeners upon thisCheckboxMenuItem.Object[]Returns the array (length 1) containing the checkbox menu item label or null if the checkbox is not selected.booleangetState()Determines whether the state of this check box menu item is "on" or "off."Returns a string representing the state of thisCheckBoxMenuItem.protected voidProcesses events on this check box menu item.protected voidProcesses item events occurring on this check box menu item by dispatching them to any registeredItemListenerobjects.voidRemoves the specified item listener so that it no longer receives item events from this check box menu item.voidsetState(boolean b) Sets this check box menu item to the specified state.Methods declared in class java.awt.MenuItemaddActionListener, deleteShortcut, disable, disableEvents, enable, enable, enableEvents, getActionCommand, getActionListeners, getLabel, getShortcut, isEnabled, processActionEvent, removeActionListener, setActionCommand, setEnabled, setLabel, setShortcutMethods declared in class java.awt.MenuComponentdispatchEvent, getFont, getName, getParent, getTreeLock, postEvent, removeNotify, setFont, setName, toString
- 
Constructor Details- 
CheckboxMenuItemCreate a check box menu item with an empty label. The item's state is initially set to "off."- Throws:
- HeadlessException- if GraphicsEnvironment.isHeadless() returns true
- Since:
- 1.1
- See Also:
 
- 
CheckboxMenuItemCreate a check box menu item with the specified label. The item's state is initially set to "off."- Parameters:
- label- a string label for the check box menu item, or- nullfor an unlabeled menu item.
- Throws:
- HeadlessException- if GraphicsEnvironment.isHeadless() returns true
- See Also:
 
- 
CheckboxMenuItemCreate a check box menu item with the specified label and state.- Parameters:
- label- a string label for the check box menu item, or- nullfor an unlabeled menu item.
- state- the initial state of the menu item, where- trueindicates "on" and- falseindicates "off."
- Throws:
- HeadlessException- if GraphicsEnvironment.isHeadless() returns true
- Since:
- 1.1
- See Also:
 
 
- 
- 
Method Details- 
addNotifypublic void 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.
- 
getStatepublic boolean getState()Determines whether the state of this check box menu item is "on" or "off."- Returns:
- the state of this check box menu item, where
                     trueindicates "on" andfalseindicates "off"
- See Also:
 
- 
setStatepublic void setState(boolean b) Sets this check box menu item to the specified state. The boolean valuetrueindicates "on" whilefalseindicates "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 anItemEventis by user interaction.- Parameters:
- b-- trueif the check box menu item is on, otherwise- false
- See Also:
 
- 
getSelectedObjectsReturns the array (length 1) containing the checkbox menu item label or null if the checkbox is not selected.- Specified by:
- getSelectedObjectsin interface- ItemSelectable
- Returns:
- the list of selected objects, or null
- See Also:
 
- 
addItemListenerAdds 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. - Specified by:
- addItemListenerin interface- ItemSelectable
- Parameters:
- l- the item listener
- Since:
- 1.1
- See Also:
 
- 
removeItemListenerRemoves 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. - Specified by:
- removeItemListenerin interface- ItemSelectable
- Parameters:
- l- the item listener
- Since:
- 1.1
- See Also:
 
- 
getItemListenersReturns an array of all the item listeners registered on this checkbox menuitem.- Returns:
- all of this checkbox menuitem's ItemListeners or an empty array if no item listeners are currently registered
- Since:
- 1.4
- See Also:
 
- 
getListenersReturns an array of all the objects currently registered asFooListeners upon thisCheckboxMenuItem.FooListeners are registered using theaddFooListenermethod.You can specify the listenerTypeargument with a class literal, such asFooListener.class. For example, you can query aCheckboxMenuItem cfor 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.- Overrides:
- getListenersin class- MenuItem
- Type Parameters:
- T- the type of the listeners
- Parameters:
- listenerType- the type of listeners requested; this parameter should specify an interface that descends from- java.util.EventListener
- Returns:
- an array of all objects registered as
          FooListeners on this checkbox menuitem, or an empty array if no such listeners have been added
- Throws:
- ClassCastException- if- listenerTypedoesn't specify a class or interface that implements- java.util.EventListener
- Since:
- 1.3
- See Also:
 
- 
processEventProcesses events on this check box menu item. If the event is an instance ofItemEvent, this method invokes theprocessItemEventmethod. If the event is not an item event, it invokesprocessEventon the superclass.Check box menu items currently support only item events. Note that if the event parameter is nullthe behavior is unspecified and may result in an exception.- Overrides:
- processEventin class- MenuItem
- Parameters:
- e- the event
- Since:
- 1.1
- See Also:
 
- 
processItemEventProcesses item events occurring on this check box menu item by dispatching them to any registeredItemListenerobjects.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 ItemListenerobject is registered viaaddItemListener.
- Item events are enabled via enableEvents.
 Note that if the event parameter is nullthe behavior is unspecified and may result in an exception.- Parameters:
- e- the item event
- Since:
- 1.1
- See Also:
 
- An 
- 
paramStringReturns a string representing the state of thisCheckBoxMenuItem. 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 benull.- Overrides:
- paramStringin class- MenuItem
- Returns:
- the parameter string of this check box menu item
 
- 
getAccessibleContextGets 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.- Specified by:
- getAccessibleContextin interface- Accessible
- Overrides:
- getAccessibleContextin class- MenuItem
- Returns:
- an AccessibleAWTCheckboxMenuItem that serves as the AccessibleContext of this CheckboxMenuItem
- Since:
- 1.3
 
 
-