Swing JCheckBox

In this tutorial you will learn about the Swing JCheckBox and its application with practical example.

Swing JCheckBox

JCheckBox which inherits JToggelButton is used to create check box in Swing. This used to turn an option “on” means “true” or “off” means “false”. Clicking on Check Box it means you are changing its state from “off” to “on” or from “on” to “off”.

Table Of Contents

Constructor Summary: Let’s get more understand about JCheckBox , Some of important constructor are listed below.

JCheckBox() : This constructor construct a new checkbox with unselected state and no text , no icon.

JCheckBox(String text): This constructor construct a new checkbox button with unselected state and with text.

JCheckBox(Icon icon): This constructor construct a new checkbox button with unselected state and with icon.

JCheckBox(String text, boolean selected): This constructor construct a new checkbox with text and specify whether or not it is initially selected.

JCheckBox(String text, Icon icon): This constructor is used to construct a new checkbox button with text and with icon.

JCheckBox(String text, Icon icon, boolean selected): This constructor is used to construct a new checkbox button with text, icon and specify whether or not it is initially selected.

JCheckBox(Action a): Construct a checkbox where properties are taken from the Action supplied.

 

JCheckBox Method

Some of commonly used methods are listed below. It will help to know more about JCheckBox.

AccessibleContext getAccessibleContext(): Used to gets the AccessibleContext which is associated with this JCheckBox.

void updateUI(): This method is used to resets the UI property to a value from the current look and feel.

protected String paramString(): This method returns string representation of this JCheckBox.

Example :-

An simple example to get understand about JCheckBox. Hopefully this will work for you.

Output :-

Output of this code will look like below image. You just need to copy this code and paste it in you program.

image001

In this tutorial we have learn about the Swing JCheckBox and its application with practical example. I hope you will like this tutorial.