0% found this document useful (0 votes)
17 views3 pages

JCheckbox

JCheckbox
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views3 pages

JCheckbox

JCheckbox
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Java JCheckBox

The JCheckBox class is used to create a checkbox. It is used to turn an


option on (true) or off (false). Clicking on a CheckBox changes its state
from "on" to "off" or from "off" to "on ".It inherits JToggleButton class.

JCheckBox class declaration


Let's see the declaration for javax.swing.JCheckBox class.

1. public class JCheckBox extends JToggleButton implements Acces


sible

Commonly used Constructors:

Constructor Description

JJCheckBox() Creates an initially unselected check box button w


text, no icon.

JChechBox(String s) Creates an initially unselected check box with text

JCheckBox(String text, boolean Creates a check box with text and specifies whet
selected) not it is initially selected.

JCheckBox(Action a) Creates a check box where properties are taken fro


Action supplied.

Commonly used Methods:

Methods Description

AccessibleContext It is used to get the AccessibleContext associate


getAccessibleContext() this JCheckBox.

protected String paramString() It returns a string representation of this JCheckB


Java JCheckBox Example
1. import javax.swing.*;
2. public class CheckBoxExample
3. {
4. CheckBoxExample(){
5. JFrame f= new JFrame("CheckBox Example");
6. JCheckBox checkBox1 = new JCheckBox("C++");
7. checkBox1.setBounds(100,100, 50,50);
8. JCheckBox checkBox2 = new JCheckBox("Java", true);
9. checkBox2.setBounds(100,150, 50,50);
10. f.add(checkBox1);
11. f.add(checkBox2);
12. f.setSize(400,400);
13. f.setLayout(null);
14. f.setVisible(true);
15. }
16. public static void main(String args[])
17. {
18. new CheckBoxExample();
19. }}

Output:

You might also like