ItemSelectable
, Serializable
, Accessible
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 Classes
protected class
Inner class of CheckboxMenuItem used to provide default support for accessibility.
Constructors
Create a check box menu item with an empty label.
Create a check box menu item with the specified label.
Create a check box menu item with the specified label and state.
void
Adds the specified item listener to receive item events from this check box menu item.
void
Creates 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.
Returns an array of all the objects currently registered as FooListener
s upon this CheckboxMenuItem
.
Returns the array (length 1) containing the checkbox menu item label or null if the checkbox is not selected.
boolean
Determines whether the state of this check box menu item is "on" or "off."
Returns a string representing the state of this CheckBoxMenuItem
.
protected void
Processes events on this check box menu item.
protected void
Processes item events occurring on this check box menu item by dispatching them to any registered ItemListener
objects.
void
Removes the specified item listener so that it no longer receives item events from this check box menu item.
void
Sets this check box menu item to the specified state.
addActionListener, deleteShortcut, disable, disableEvents, enable, enable, enableEvents, getActionCommand, getActionListeners, getLabel, getShortcut, isEnabled, processActionEvent, removeActionListener, setActionCommand, setEnabled, setLabel, setShortcut
Create a check box menu item with an empty label. The item's state is initially set to "off."
HeadlessException
- if GraphicsEnvironment.isHeadless() returns true
Create a check box menu item with the specified label. The item's state is initially set to "off."
label
- a string label for the check box menu item, or null
for an unlabeled menu item.
HeadlessException
- if GraphicsEnvironment.isHeadless() returns true
Create a check box menu item with the specified label and state.
label
- a string label for the check box menu item, or null
for an unlabeled menu item.
state
- the initial state of the menu item, where true
indicates "on" and false
indicates "off."
HeadlessException
- if GraphicsEnvironment.isHeadless() returns true
public 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.
public boolean getState()
Determines whether the state of this check box menu item is "on" or "off."
true
indicates "on" and false
indicates "off"
public 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.
b
- true
if the check box menu item is on, otherwise false
()
Returns the array (length 1) containing the checkbox menu item label or null if the checkbox is not selected.
getSelectedObjects
in interface ItemSelectable
null
Refer to AWT Threading Issues for details on AWT's threading model.
addItemListener
in interface ItemSelectable
l
- the item listener
Refer to AWT Threading Issues for details on AWT's threading model.
removeItemListener
in interface ItemSelectable
l
- the item listener
Returns an array of all the item listeners registered on this checkbox menuitem.
ItemListener
s or an empty array if no item listeners are currently registered
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.
getListeners
in class MenuItem
T
- the type of the listeners
listenerType
- the type of listeners requested; this parameter should specify an interface that descends from java.util.EventListener
FooListener
s on this checkbox menuitem, or an empty array if no such listeners have been added
ClassCastException
- if listenerType
doesn't specify a class or interface that implements java.util.EventListener
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.
processEvent
in class MenuItem
e
- the event
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:
ItemListener
object is registered via addItemListener
.enableEvents
.Note that if the event parameter is null
the behavior is unspecified and may result in an exception.
e
- the item event
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
.
paramString
in class MenuItem
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.
getAccessibleContext
in interface Accessible
getAccessibleContext
in class MenuItem
Report a bug or suggest an enhancement
For further API reference and developer documentation see the Java SE Documentation, which contains more detailed, developer-targeted descriptions with conceptual overviews, definitions of terms, workarounds, and working code examples. Other versions.
Java is a trademark or registered trademark of Oracle and/or its affiliates in the US and other countries.
Copyright © 1993, 2022, Oracle and/or its affiliates, 500 Oracle Parkway, Redwood Shores, CA 94065 USA.
All rights reserved. Use is subject to license terms and the documentation redistribution policy.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4