Creating Check Box in Java Swing

This section illustrates you how to create a Check Box
component in Java Swing.
In this section, you can learn simply creating the
Check Box in Java Swing. Check Boxes are created in swing by creating the
instance of the JCheckBox class using it's constructor which contains the
string which has to be shown beside the check box on the frame or window like
this:

This
is written like:
JCheckBox chk = new JCheckBox("This
is the Check Box");
This component of the javax.swing.*; is added to
the frame using the add(component) method of the JFrame class.
Here is the code of the program:
import javax.swing.*;
public class CreateCheckBox{
public static void main(String[] args){
JFrame frame = new JFrame("Check Box Frame");
JCheckBox chk = new JCheckBox("This is the Check Box");
frame.add(chk);
frame.setSize(400, 400);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
|
Download this example.

|
Current Comments
2 comments so far (post your own) View All Comments Latest 10 Comments:Yes, Really good , but without knowing awt can I learn swing Plz clarrify my doubt
Posted by uday on Friday, 08.24.07 @ 17:42pm | #24047
Actually i don't know anything about swing.When i go through this site its very easy to learn.This site contains good syntaxes , example programs with code.
This site is very helpful for me .....
Posted by Gokul Kumar D on Wednesday, 02.7.07 @ 18:12pm | #6622