| |
|
| java.lang.Object java.awt.MenuComponent java.awt.MenuItem java.awt.CheckboxMenuItem
CheckboxMenuItem | public class CheckboxMenuItem extends MenuItem implements ItemSelectable,Accessible(Code) | | 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.
version: 1.79, 05/05/07 author: Sami Shaio See Also: java.awt.event.ItemEvent See Also: java.awt.event.ItemListener since: JDK1.0 |
Constructor Summary | |
public | CheckboxMenuItem() Create a check box menu item with an empty label. | public | CheckboxMenuItem(String label) Create a check box menu item with the specified label. | public | CheckboxMenuItem(String label, boolean state) Create a check box menu item with the specified label and state. |
Method Summary | |
public synchronized void | addItemListener(ItemListener l) Adds the specified item listener to receive item events from
this check box menu item. | public void | addNotify() Creates the peer of the checkbox item. | String | constructComponentName() Construct a name for this MenuComponent. | void | doMenuEvent(long when, int modifiers) | boolean | eventEnabled(AWTEvent e) | public AccessibleContext | getAccessibleContext() Gets the AccessibleContext associated with this CheckboxMenuItem. | public synchronized ItemListener[] | getItemListeners() Returns an array of all the item listeners
registered on this checkbox menuitem. | public T[] | getListeners(Class<T> listenerType) Returns an array of all the objects currently registered
as FooListener s
upon this CheckboxMenuItem . | public synchronized Object[] | getSelectedObjects() Returns the an array (length 1) containing the checkbox menu item
label or null if the checkbox is not selected. | public boolean | getState() | public 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.
This method is not called unless item events are
enabled for this menu item. | public synchronized void | removeItemListener(ItemListener l) Removes the specified item listener so that it no longer receives
item events from this check box menu item. | public synchronized void | setState(boolean b) Sets this check box menu item to the specifed 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. |
CheckboxMenuItem | public CheckboxMenuItem(String label, boolean state) throws HeadlessException(Code) | | Create a check box menu item with the specified label and state.
Parameters: label - a string label for the check box menu item, or null for an unlabeled menu item. Parameters: state - the initial state of the menu item, wheretrue indicates "on" andfalse indicates "off." exception: HeadlessException - if GraphicsEnvironment.isHeadless()returns true See Also: java.awt.GraphicsEnvironment.isHeadless since: JDK1.1 |
constructComponentName | String constructComponentName()(Code) | | Construct a name for this MenuComponent. Called by getName() when
the name is null.
|
doMenuEvent | void doMenuEvent(long when, int modifiers)(Code) | | |
getAccessibleContext | public AccessibleContext getAccessibleContext()(Code) | | 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.
an AccessibleAWTCheckboxMenuItem that serves as the AccessibleContext of this CheckboxMenuItem since: 1.3 |
getListeners | public T[] getListeners(Class<T> listenerType)(Code) | | Returns an array of all the objects currently registered
as FooListener s
upon this CheckboxMenuItem .
FooListener s 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 - the type of listeners requested; this parametershould specify an interface that descends fromjava.util.EventListener an array of all objects registered asFooListener s on this checkbox menuitem,or an empty array if no suchlisteners have been added exception: ClassCastException - if listenerType doesn't specify a class or interface that implementsjava.util.EventListener See Also: CheckboxMenuItem.getItemListeners since: 1.3 |
getSelectedObjects | public synchronized Object[] getSelectedObjects()(Code) | | Returns the an array (length 1) containing the checkbox menu item
label or null if the checkbox is not selected.
See Also: ItemSelectable |
getState | public boolean getState()(Code) | | Determines whether the state of this check box menu item
is "on" or "off."
the state of this check box menu item, wheretrue indicates "on" andfalse indicates "off" See Also: CheckboxMenuItem.setState |
paramString | public String paramString()(Code) | | 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 .
the parameter string of this check box menu item |
processEvent | protected void processEvent(AWTEvent e)(Code) | | 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 - the event See Also: java.awt.event.ItemEvent See Also: CheckboxMenuItem.processItemEvent since: JDK1.1 |
processItemEvent | protected void processItemEvent(ItemEvent e)(Code) | | 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 - the item event See Also: java.awt.event.ItemEvent See Also: java.awt.event.ItemListener See Also: CheckboxMenuItem.addItemListener See Also: java.awt.MenuItem.enableEvents since: JDK1.1 |
setState | public synchronized void setState(boolean b)(Code) | | Sets this check box menu item to the specifed 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 - true if the check boxmenu item is on, otherwise false See Also: CheckboxMenuItem.getState |
|
|
|