APIdia Launch Partner
Top Description Inners Fields Constructors Methods
javax.swing

public Class JCheckBox

extends JToggleButton
implements Accessible
Class Inheritance
All Implemented Interfaces
javax.accessibility.Accessible
Known Direct Subclasses
javax.swing.JTable.BooleanRenderer, javax.swing.plaf.synth.SynthTableUI.SynthBooleanTableCellRenderer
Annotations
@JavaBean
description:A component which can be selected or deselected.
@SwingContainer:false
@SuppressWarnings:serial
Imports
java.beans.BeanProperty, .JavaBean, java.io.IOException, .ObjectInputStream, .ObjectOutputStream, .Serial, javax.accessibility.Accessible, .AccessibleContext, .AccessibleRole, javax.swing.plaf.ButtonUI

An implementation of a check box -- an item that can be selected or deselected, and which displays its state to the user. By convention, any number of check boxes in a group can be selected. See How to Use Buttons, Check Boxes, and Radio Buttons in The Java Tutorial for examples and information on using check boxes.

Buttons can be configured, and to some degree controlled, by Actions. Using an Action with a button has many benefits beyond directly configuring a button. Refer to Swing Components Supporting Action for more details, and you can find more information in How to Use Actions, a section in The Java Tutorial.

Warning

Swing is not thread safe. For more information see Swing's Threading Policy.

Warning

Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeans has been added to the java.beans package. Please see java.beans.XMLEncoder.

Author
Jeff Dinkins
Since
1.2
See Also
JRadioButton

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected class
JCheckBox.AccessibleJCheckBox

This class implements accessibility support for the JCheckBox class.

Field Summary

Modifier and TypeField and Description
public static final String
BORDER_PAINTED_FLAT_CHANGED_PROPERTY

Identifies a change to the flat property.

private boolean
private static final String

Constructor Summary

AccessConstructor and Description
public
JCheckBox()

Creates an initially unselected check box button with no text, no icon.

public
JCheckBox(Icon
the Icon image to display
icon
)

Creates an initially unselected check box with an icon.

public
JCheckBox(Icon
the Icon image to display
icon
,
boolean
a boolean value indicating the initial selection state. If true the check box is selected
selected
)

Creates a check box with an icon and specifies whether or not it is initially selected.

public
JCheckBox(String
the text of the check box.
text
)

Creates an initially unselected check box with text.

public
JCheckBox(Action
the Action used to specify the new check box
a
)

Creates a check box where properties are taken from the Action supplied.

public
JCheckBox(String
the text of the check box.
text
,
boolean
a boolean value indicating the initial selection state. If true the check box is selected
selected
)

Creates a check box with text and specifies whether or not it is initially selected.

public
JCheckBox(String
the text of the check box.
text
,
Icon
the Icon image to display
icon
)

Creates an initially unselected check box with the specified text and icon.

public
JCheckBox(String
the text of the check box.
text
,
Icon
the Icon image to display
icon
,
boolean
a boolean value indicating the initial selection state. If true the check box is selected
selected
)

Creates a check box with text and icon, and specifies whether or not it is initially selected.

Method Summary

Modifier and TypeMethod and Description
public AccessibleContext

Returns:

an AccessibleJCheckBox that serves as the AccessibleContext of this JCheckBox
getAccessibleContext
()

Overrides javax.swing.JToggleButton.getAccessibleContext.

Implements javax.accessibility.Accessible.getAccessibleContext.

Gets the AccessibleContext associated with this JCheckBox.

public String

Returns:

the string "CheckBoxUI"
getUIClassID
()

Overrides javax.swing.JToggleButton.getUIClassID.

Returns a string that specifies the name of the L&F class that renders this component.

public boolean

Returns:

the value of the borderPaintedFlat property
isBorderPaintedFlat
()

Gets the value of the borderPaintedFlat property.

protected String

Returns:

a string representation of this JCheckBox.
paramString
()

Overrides javax.swing.JToggleButton.paramString.

Returns a string representation of this JCheckBox.

private void
readObject(ObjectInputStream s)

Hides javax.swing.JComponent.readObject.

See JComponent.readObject() for information about serialization in Swing.

public void
setBorderPaintedFlat(boolean
true requests that the border be painted flat; false requests normal borders
b
)

Sets the borderPaintedFlat property, which gives a hint to the look and feel as to the appearance of the check box border.

pack-priv void
setIconFromAction(Action a)

Overrides javax.swing.AbstractButton.setIconFromAction.

The icon for checkboxes comes from the look and feel, not the Action; this is overridden to do nothing.

public void
updateUI()

Overrides javax.swing.JToggleButton.updateUI.

Resets the UI property to a value from the current look and feel.

private void
writeObject(ObjectOutputStream s)

Hides javax.swing.JToggleButton.writeObject.

See readObject() and writeObject() in JComponent for more information about serialization in Swing.

Inherited from javax.swing.JToggleButton:
requestFocusrequestFocusInWindowshouldUpdateSelectedStateFromAction

Field Detail

BORDER_PAINTED_FLAT_CHANGED_PROPERTYback to summary
public static final String BORDER_PAINTED_FLAT_CHANGED_PROPERTY

Identifies a change to the flat property.

flatback to summary
private boolean flat
uiClassIDback to summary
private static final String uiClassID

Hides javax.swing.JToggleButton.uiClassID.

See Also
getUIClassID, readObject

Constructor Detail

JCheckBoxback to summary
public JCheckBox()

Creates an initially unselected check box button with no text, no icon.

JCheckBoxback to summary
public JCheckBox(Icon icon)

Creates an initially unselected check box with an icon.

Parameters
icon:Icon

the Icon image to display

JCheckBoxback to summary
public JCheckBox(Icon icon, boolean selected)

Creates a check box with an icon and specifies whether or not it is initially selected.

Parameters
icon:Icon

the Icon image to display

selected:boolean

a boolean value indicating the initial selection state. If true the check box is selected

JCheckBoxback to summary
public JCheckBox(String text)

Creates an initially unselected check box with text.

Parameters
text:String

the text of the check box.

JCheckBoxback to summary
public JCheckBox(Action a)

Creates a check box where properties are taken from the Action supplied.

Parameters
a:Action

the Action used to specify the new check box

Since
1.3
JCheckBoxback to summary
public JCheckBox(String text, boolean selected)

Creates a check box with text and specifies whether or not it is initially selected.

Parameters
text:String

the text of the check box.

selected:boolean

a boolean value indicating the initial selection state. If true the check box is selected

JCheckBoxback to summary
public JCheckBox(String text, Icon icon)

Creates an initially unselected check box with the specified text and icon.

Parameters
text:String

the text of the check box.

icon:Icon

the Icon image to display

JCheckBoxback to summary
public JCheckBox(String text, Icon icon, boolean selected)

Creates a check box with text and icon, and specifies whether or not it is initially selected.

Parameters
text:String

the text of the check box.

icon:Icon

the Icon image to display

selected:boolean

a boolean value indicating the initial selection state. If true the check box is selected

Method Detail

getAccessibleContextback to summary
public AccessibleContext getAccessibleContext()

Overrides javax.swing.JToggleButton.getAccessibleContext.

Implements javax.accessibility.Accessible.getAccessibleContext.

Gets the AccessibleContext associated with this JCheckBox. For JCheckBoxes, the AccessibleContext takes the form of an AccessibleJCheckBox. A new AccessibleJCheckBox instance is created if necessary.

Returns:AccessibleContext

an AccessibleJCheckBox that serves as the AccessibleContext of this JCheckBox

Annotations
@BeanProperty
bound:false
expert:true
description:The AccessibleContext associated with this CheckBox.
getUIClassIDback to summary
public String getUIClassID()

Overrides javax.swing.JToggleButton.getUIClassID.

Returns a string that specifies the name of the L&F class that renders this component.

Returns:String

the string "CheckBoxUI"

Annotations
@BeanProperty
bound:false
expert:true
description:A string that specifies the name of the L&F class
See Also
JComponent#getUIClassID, UIDefaults#getUI
isBorderPaintedFlatback to summary
public boolean isBorderPaintedFlat()

Gets the value of the borderPaintedFlat property.

Returns:boolean

the value of the borderPaintedFlat property

Since
1.3
See Also
setBorderPaintedFlat
paramStringback to summary
protected String paramString()

Overrides javax.swing.JToggleButton.paramString.

Returns a string representation of this JCheckBox. 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. specific new aspects of the JFC components.

Returns:String

a string representation of this JCheckBox.

readObjectback to summary
private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException

Hides javax.swing.JComponent.readObject.

See JComponent.readObject() for information about serialization in Swing.

Annotations
@Serial
Exceptions
IOException:

Doc from java.awt.Container.readObject.

if an I/O error occurs

ClassNotFoundException:

Doc from java.awt.Container.readObject.

if the class of a serialized object could not be found

setBorderPaintedFlatback to summary
public void setBorderPaintedFlat(boolean b)

Sets the borderPaintedFlat property, which gives a hint to the look and feel as to the appearance of the check box border. This is usually set to true when a JCheckBox instance is used as a renderer in a component such as a JTable or JTree. The default value for the borderPaintedFlat property is false. This method fires a property changed event. Some look and feels might not implement flat borders; they will ignore this property.

Parameters
b:boolean

true requests that the border be painted flat; false requests normal borders

Annotations
@BeanProperty
visualUpdate:true
description:Whether the border is painted flat.
Since
1.3
See Also
isBorderPaintedFlat
setIconFromActionback to summary
pack-priv void setIconFromAction(Action a)

Overrides javax.swing.AbstractButton.setIconFromAction.

The icon for checkboxes comes from the look and feel, not the Action; this is overridden to do nothing.

updateUIback to summary
public void updateUI()

Overrides javax.swing.JToggleButton.updateUI.

Resets the UI property to a value from the current look and feel.

See Also
JComponent#updateUI
writeObjectback to summary
private void writeObject(ObjectOutputStream s) throws IOException

Hides javax.swing.JToggleButton.writeObject.

Doc from javax.swing.JToggleButton.writeObject.

See readObject() and writeObject() in JComponent for more information about serialization in Swing.

Annotations
@Serial
Exceptions
IOException:

Doc from java.awt.Container.writeObject.

if an I/O error occurs

javax.swing back to summary

protected Class JCheckBox.AccessibleJCheckBox

extends AccessibleJToggleButton
Class Inheritance
Known Direct Subclasses
javax.swing.JTable.BooleanRenderer.AccessibleBooleanRenderer
Annotations
@SuppressWarnings:serial

This class implements accessibility support for the JCheckBox class. It provides an implementation of the Java Accessibility API appropriate to check box user-interface elements.

Warning

Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeans has been added to the java.beans package. Please see java.beans.XMLEncoder.

Constructor Summary

AccessConstructor and Description
protected
AccessibleJCheckBox()

Constructs an AccessibleJCheckBox.

Method Summary

Modifier and TypeMethod and Description
public AccessibleRole

Returns:

an instance of AccessibleRole describing the role of the object
getAccessibleRole
()

Overrides javax.swing.JToggleButton.AccessibleJToggleButton.getAccessibleRole.

Get the role of this object.

Inherited from javax.swing.JToggleButton.AccessibleJToggleButton:
itemStateChanged

Constructor Detail

AccessibleJCheckBoxback to summary
protected AccessibleJCheckBox()

Constructs an AccessibleJCheckBox.

Method Detail

getAccessibleRoleback to summary
public AccessibleRole getAccessibleRole()

Overrides javax.swing.JToggleButton.AccessibleJToggleButton.getAccessibleRole.

Get the role of this object.

Returns:AccessibleRole

an instance of AccessibleRole describing the role of the object

See Also
AccessibleRole