is new.
java.lang.Objectjava.awt.MenuComponent
java.awt.MenuItem
java.awt.CheckboxMenuItem
public class CheckboxMenuItem
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:
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.
| Nested Class Summary | |
|---|---|
| protected class |
CheckboxMenuItem.AccessibleAWTCheckboxMenuItem
Inner class of CheckboxMenuItem used to provide default support for accessibility. |
| Nested classes/interfaces inherited from class java.awt. MenuItem |
|---|
| MenuItem.AccessibleAWTMenuItem |
| Nested classes/interfaces inherited from class java.awt. MenuComponent |
|---|
| MenuComponent.AccessibleAWTMenuComponent |
| Constructor Summary | |
|---|---|
|
CheckboxMenuItem
() Create 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 Summary | ||
|---|---|---|
| void |
addItemListener
(
ItemListener
l) Adds the specified item listener to receive item events from this check box menu item. |
|
| void |
addNotify
() Creates the peer of the checkbox item. |
|
| AccessibleContext |
getAccessibleContext
() Gets the AccessibleContext associated with this CheckboxMenuItem. |
|
| ItemListener [] |
getItemListeners
() Returns an array of all the item listeners registered on this checkbox menuitem. |
|
|
getListeners
(
Class
<T> listenerType) Returns an array of all the objects currently registered as FooListeners upon this CheckboxMenuItem. |
|
| Object [] |
getSelectedObjects
() Returns the an array (length 1) containing the checkbox menu item label or null if the checkbox is not selected. |
|
| boolean |
getState
() Determines whether the state of this check box menu item is "on" or "off." |
|
| String |
paramString
() Returns a string representing the state of this CheckBoxMenuItem. |
|
| protected void |
processEvent
(
AWTEvent
e) Processes events on this check box menu item. |
|
| protected void |
processItemEvent
(
ItemEvent
e) Processes item events occurring on this check box menu item by dispatching them to any registered ItemListener objects. |
|
| void |
removeItemListener
(
ItemListener
l) Removes the specified item listener so that it no longer receives item events from this check box menu item. |
|
| void |
setState
(boolean b) Sets this check box menu item to the specifed state. |
|
| Methods inherited from class java.awt. MenuItem |
|---|
| addActionListener , deleteShortcut , disable , disableEvents , enable , enable , enableEvents , getActionCommand , getActionListeners , getLabel , getShortcut , isEnabled , processActionEvent , removeActionListener , setActionCommand , setEnabled , setLabel , setShortcut |
| Methods inherited from class java.awt. MenuComponent |
|---|
| dispatchEvent , getFont , getName , getParent , getPeer , getTreeLock , postEvent , removeNotify , setFont , setName , toString |
| Methods inherited from class java.lang. Object |
|---|
| clone , equals , finalize , getClass , hashCode , notify , notifyAll , wait , wait , wait |
| Constructor Detail |
|---|
public CheckboxMenuItem()
throws HeadlessException
public CheckboxMenuItem(String label)
throws HeadlessException
public CheckboxMenuItem(String label,
boolean state)
throws HeadlessException
| Method Detail |
|---|
public void addNotify()
public boolean getState()
public void setState(boolean b)
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.
public Object[] getSelectedObjects()
public void addItemListener(ItemListener l)
Refer to
AWT Threading Issues
for details on AWT's threading model.
public void removeItemListener(ItemListener l)
Refer to
AWT Threading Issues
for details on AWT's threading model.
public ItemListener[] getItemListeners()
public <T extends EventListener> T[] getListeners(Class<T> listenerType)
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.
protected void processEvent(AWTEvent e)
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.
protected void processItemEvent(ItemEvent e)
This method is not called unless item events are enabled for this menu item. Item events are enabled when one of the following occurs:
Note that if the event parameter is null the behavior is unspecified and may result in an exception.
public String paramString()
public AccessibleContext getAccessibleContext()
Since:
1.3