true) or "off" (false) state.
Clicking on a check box changes its state from
"on" to "off," or from "off" to "on."
The following code example creates a set of check boxes in a grid layout:
setLayout(new GridLayout(3, 1));
add(new Checkbox("one", null, true));
add(new Checkbox("two"));
add(new Checkbox("three"));
This image depicts the check boxes and grid layout created by this code example:
The button labeled one is in the "on" state, and the
other two are in the "off" state. In this example, which uses the
GridLayout class, the states of the three check
boxes are set independently.
Alternatively, several check boxes can be grouped together under
the control of a single object, using the
CheckboxGroup class.
In a check box group, at most one button can be in the "on"
state at any given time. Clicking on a check box to turn it on
forces any other check box in the same group that is on
into the "off" state.
java.awt.GridLayout , java.awt.CheckboxGroup
| Modifier and Type | Class and Description |
|---|---|
| protected class | Checkbox.
This class implements accessibility support for the
|
| Modifier and Type | Field and Description |
|---|---|
| private static final String | |
| private int | checkboxSerializedDataVersion
Serialized data version. |
| pack-priv CheckboxGroup | group
The check box group. |
| pack-priv transient ItemListener | |
| pack-priv String | label
The label of the Checkbox. |
| private static int | |
| private static final long | serialVersionUID
Use serialVersionUID from JDK 1.1 for interoperability.
|
| pack-priv boolean | state
The state of the |
| Access | Constructor and Description |
|---|---|
| public | |
| public | |
| public | |
| public | Checkbox(String
a string label for this check box,
or label, boolean null for no label.the initial state of this check box. state, CheckboxGroup a check box group for this check box,
or group)null for no group.Constructs a Checkbox with the specified label, set to the specified state, and in the specified check box group. |
| public | Checkbox(String
a string label for this check box,
or label, CheckboxGroup null for no label.a check box group for this check box,
or group, boolean null for no group.the initial state of this check box. state)Creates a check box with the specified label, in the specified check box group, and set to the specified state. |
| Modifier and Type | Method and Description |
|---|---|
| public synchronized void | addItemListener(ItemListener
the item listener l)Implements java. Adds the specified item listener to receive item events from this check box. |
| public void | |
| pack-priv String | Returns: a name for this componentOverrides java. Constructs a name for this component. |
| pack-priv boolean | |
| public AccessibleContext | Returns: an AccessibleAWTCheckbox that serves as the AccessibleContext of this CheckboxOverrides java. Implements javax. Gets the AccessibleContext associated with this Checkbox. |
| public CheckboxGroup | Returns: this check box's group, ornull
if the check box is not part of a check box group.Determines this check box's group. |
| public synchronized ItemListener[] | Returns: all of this checkbox'sItemListeners
or an empty array if no item
listeners are currently registeredReturns an array of all the item listeners registered on this checkbox. |
| public String | Returns: the label of this check box, ornull
if this check box has no label.Gets the label of this check box. |
| public <T extends EventListener> T[] | Returns: an array of all objects registered asFooListeners on this checkbox,
or an empty array if no such
listeners have been addedthe type of listeners requested; this parameter
should specify an interface that descends from
listenerType)java.util.EventListenerOverrides java. Returns an array of all the objects currently registered
as |
| public Object[] | getSelectedObjects()
Implements java. Returns an array (length 1) containing the checkbox label or null if the checkbox is not selected. |
| public boolean | Returns: the state of this check box, as a boolean valueDetermines whether this check box is in the "on" or "off" state. |
| private static native void | |
| protected String | Returns: the parameter string of this check boxOverrides java. Returns a string representing the state of this |
| protected void | processEvent(AWTEvent
the event e)Overrides java. Processes events on this check box. |
| protected void | processItemEvent(ItemEvent
the item event e)Processes item events occurring on this check box by
dispatching them to any registered
|
| private void | readObject(ObjectInputStream
the s)ObjectInputStream to readHides java. Reads the |
| public synchronized void | removeItemListener(ItemListener
the item listener l)Implements java. Removes the specified item listener so that the item listener no longer receives item events from this check box. |
| public void | setCheckboxGroup(CheckboxGroup
the new check box group, or g)null
to remove this check box from any check box groupSets this check box's group to the specified check box group. |
| public void | |
| public void | setState(boolean
the boolean state of the check box state)Sets the state of this check box to the specified state. |
| pack-priv void | setStateInternal(boolean state)
Helper function for setState and CheckboxGroup.setSelectedCheckbox Should remain package-private. |
| private void | writeObject(ObjectOutputStream
the s)ObjectOutputStream to writeHides java. Writes default serializable fields to stream. |
| base | back to summary |
|---|---|
| private static final String base | |
| checkboxSerializedDataVersion | back to summary |
|---|---|
| private int checkboxSerializedDataVersion Serialized data version. | |
| group | back to summary |
|---|---|
| pack-priv CheckboxGroup group The check box group. This field can be null indicating that the checkbox is not a group checkbox. | |
| itemListener | back to summary |
|---|---|
| pack-priv transient ItemListener itemListener | |
| label | back to summary |
|---|---|
| pack-priv String label The label of the Checkbox. This field can be null.
| |
| nameCounter | back to summary |
|---|---|
| private static int nameCounter | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID Hides java. Use serialVersionUID from JDK 1.1 for interoperability. | |
| state | back to summary |
|---|---|
| pack-priv boolean state The state of the
| |
| Checkbox | back to summary |
|---|---|
| public Checkbox() throws HeadlessException Creates a check box with an empty string for its label. The state of this check box is set to "off," and it is not part of any check box group.
| |
| Checkbox | back to summary |
|---|---|
| public Checkbox(String label) throws HeadlessException Creates a check box with the specified label. The state of this check box is set to "off," and it is not part of any check box group.
| |
| Checkbox | back to summary |
|---|---|
| public Checkbox(String label, boolean state) throws HeadlessException Creates a check box with the specified label and sets the specified state. This check box is not part of any check box group.
| |
| Checkbox | back to summary |
|---|---|
| public Checkbox(String label, boolean state, CheckboxGroup group) throws HeadlessException Constructs a Checkbox with the specified label, set to the specified state, and in the specified check box group.
| |
| Checkbox | back to summary |
|---|---|
| public Checkbox(String label, CheckboxGroup group, boolean state) throws HeadlessException Creates a check box with the specified label, in the specified check box group, and set to the specified state.
| |
| addItemListener | back to summary |
|---|---|
| public synchronized void addItemListener(ItemListener l) Implements java. Adds the specified item listener to receive item events from this check box. Item events are sent to listeners in response to user input, 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.
| |
| addNotify | back to summary |
|---|---|
| public void addNotify() Overrides java. Creates the peer of the Checkbox. The peer allows you to change the look of the Checkbox without changing its functionality.
| |
| constructComponentName | back to summary |
|---|---|
| pack-priv String constructComponentName() Overrides java. Constructs a name for this component. Called by
| |
| eventEnabled | back to summary |
|---|---|
| pack-priv boolean eventEnabled(AWTEvent e) Overrides java. | |
| getAccessibleContext | back to summary |
|---|---|
| public AccessibleContext getAccessibleContext() Overrides java. Implements javax. Gets the AccessibleContext associated with this Checkbox. For checkboxes, the AccessibleContext takes the form of an AccessibleAWTCheckbox. A new AccessibleAWTCheckbox is created if necessary.
| |
| getCheckboxGroup | back to summary |
|---|---|
| public CheckboxGroup getCheckboxGroup() Determines this check box's group.
| |
| getItemListeners | back to summary |
|---|---|
| public synchronized ItemListener[] getItemListeners() Returns an array of all the item listeners registered on this checkbox.
| |
| getLabel | back to summary |
|---|---|
| public String getLabel() Gets the label of this check box.
| |
| getListeners | back to summary |
|---|---|
| public <T extends EventListener> T[] getListeners(Class<T> listenerType) Overrides java. Returns an array of all the objects currently registered
as
You can specify the ItemListener[] ils = (ItemListener[])(c.getListeners(ItemListener.class));If no such listeners exist, this method returns an empty array.
| |
| getSelectedObjects | back to summary |
|---|---|
| public Object[] getSelectedObjects() Implements java. Returns an array (length 1) containing the checkbox label or null if the checkbox is not selected.
| |
| getState | back to summary |
|---|---|
| public boolean getState() Determines whether this check box is in the "on" or "off" state.
The boolean value
| |
| initIDs | back to summary |
|---|---|
| private static native void initIDs() Hides java. Initialize JNI field and method ids | |
| paramString | back to summary |
|---|---|
| protected String paramString() Overrides java. Returns a string representing the state of this
| |
| processEvent | back to summary |
|---|---|
| protected void processEvent(AWTEvent e) Overrides java. Processes events on this check box.
If the event is an instance of Note that if the event parameter is
| |
| processItemEvent | back to summary |
|---|---|
| protected void processItemEvent(ItemEvent e) Processes item events occurring on this check box by
dispatching them to any registered
This method is not called unless item events are enabled for this component. Item events are enabled when one of the following occurs:
Note that if the event parameter is
| |
| readObject | back to summary |
|---|---|
| private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException, HeadlessException Hides java. Reads the
| |
| removeItemListener | back to summary |
|---|---|
| public synchronized void removeItemListener(ItemListener l) Implements java. Removes the specified item listener so that the item listener no longer receives item events from this check box. 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.
| |
| setCheckboxGroup | back to summary |
|---|---|
| public void setCheckboxGroup(CheckboxGroup g) Sets this check box's group to the specified check box group. If this check box is already in a different check box group, it is first taken out of that group.
If the state of this check box is
| |
| setLabel | back to summary |
|---|---|
| public void setLabel(String label) Sets this check box's label to be the string argument. | |
| setState | back to summary |
|---|---|
| public void setState(boolean state) Sets the state of this check box to the specified state.
The boolean value Note that this method should be primarily used to
initialize the state of the checkbox. Programmatically
setting the state of the checkbox will not trigger
an
| |
| setStateInternal | back to summary |
|---|---|
| pack-priv void setStateInternal(boolean state) Helper function for setState and CheckboxGroup.setSelectedCheckbox Should remain package-private. | |
| writeObject | back to summary |
|---|---|
| private void writeObject(ObjectOutputStream s) throws IOException Hides java. Writes default serializable fields to stream. Writes
a list of serializable
| |
Checkbox class. It provides an implementation of the
Java Accessibility API appropriate to checkbox user-interface elements.
| Modifier and Type | Field and Description |
|---|---|
| private static final long | serialVersionUID
Hides java. |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | Returns: true if the action was performed; else false.zero-based index of actions i)Implements javax. Perform the specified Action on the object |
| public AccessibleAction | Returns: this objectOverrides javax. Get the AccessibleAction associated with this object. |
| public int | Returns: the number of Actions in this objectImplements javax. Returns the number of Actions available in this object. |
| public String | getAccessibleActionDescription(int
zero-based index of the actions i)Implements javax. Return a description of the specified action of the object. |
| public AccessibleRole | Returns: an instance of AccessibleRole describing the role of the objectOverrides java. Get the role of this object. |
| public AccessibleStateSet | Returns: an instance of AccessibleState containing the current state of the objectOverrides java. Get the state set of this object. |
| public AccessibleValue | Returns: this objectOverrides javax. Get the AccessibleValue associated with this object. |
| public Number | Returns: value of the objectImplements javax. Get the value of this object as a Number. |
| public Number | Returns: Maximum value of the object; null if this object does not have a maximum valueImplements javax. 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 valueImplements javax. Get the minimum value of this object as a Number. |
| public void | itemStateChanged(ItemEvent e)
Implements java. Fire accessible property change events when the state of the toggle button changes. |
| public boolean | Returns: True if the value was set; else FalseImplements javax. Set the value of this object as a Number. |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID Hides java. Use serialVersionUID from JDK 1.3 for interoperability. | |
| AccessibleAWTCheckbox | back to summary |
|---|---|
| public AccessibleAWTCheckbox() Constructor for | |
| doAccessibleAction | back to summary |
|---|---|
| public boolean doAccessibleAction(int i) Implements javax. Perform the specified Action on the object
| |
| getAccessibleAction | back to summary |
|---|---|
| public AccessibleAction getAccessibleAction() Overrides javax. 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.
| |
| getAccessibleActionCount | back to summary |
|---|---|
| public int getAccessibleActionCount() Implements javax. Returns the number of Actions available in this object. If there is more than one, the first one is the "default" action.
| |
| getAccessibleActionDescription | back to summary |
|---|---|
| public String getAccessibleActionDescription(int i) Implements javax. Return a description of the specified action of the object.
| |
| getAccessibleRole | back to summary |
|---|---|
| public AccessibleRole getAccessibleRole() Overrides java. Get the role of this object.
| |
| getAccessibleStateSet | back to summary |
|---|---|
| public AccessibleStateSet getAccessibleStateSet() Overrides java. Get the state set of this object.
| |
| getAccessibleValue | back to summary |
|---|---|
| public AccessibleValue getAccessibleValue() Overrides javax. 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.
| |
| getCurrentAccessibleValue | back to summary |
|---|---|
| public Number getCurrentAccessibleValue() Implements javax. Get the value of this object as a Number. If the value has not been set, the return value will be null.
| |
| getMaximumAccessibleValue | back to summary |
|---|---|
| public Number getMaximumAccessibleValue() Implements javax. Get the maximum value of this object as a Number.
| |
| getMinimumAccessibleValue | back to summary |
|---|---|
| public Number getMinimumAccessibleValue() Implements javax. Get the minimum value of this object as a Number.
| |
| itemStateChanged | back to summary |
|---|---|
| public void itemStateChanged(ItemEvent e) Implements java. Fire accessible property change events when the state of the toggle button changes. | |
| setCurrentAccessibleValue | back to summary |
|---|---|
| public boolean setCurrentAccessibleValue(Number n) Implements javax. Set the value of this object as a Number.
| |