Tuesday, June 17, 2008


How to Create Checkbox in Java Swing?

What is Check Box?

A check box or tick box is a graphical user interface element that allow or permits user to make selections from the options. User can select more than one item or element.

The given example will explain you how to create check box in java swing. It is created in java by creating the instance of JCheckBo class. Here is the check box program :


public class CreateCheckBox{
public static void main(String[] args){
JFrame frame = new JFrame("The Check Box Example");
JCheckBox chk = new JCheckBox("Check Box 1");
JCheckBox chk = new JCheckBox("Check Box 2");
JCheckBox chk = new JCheckBox("Check Box 3");
frame.add(chk);
frame.setSize(400, 400);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}


4 comments:

Supriya said...

this cretes at compile time i.e.at using this app.u cant create new Checkboxes.
can u tell me the that using app same time i should able to create new checjboxes as well as put it onto JPanel

Supriya said...

this cretes at compile time i.e.at using this app.u cant create new Checkboxes.
can u tell me the that using app same time i should able to create new checjboxes as well as put it onto JPanel

Supriya said...

this cretes at compile time i.e.at using this app.u cant create new Checkboxes.
can u tell me the that using app same time i should able to create new checjboxes as well as put it onto JPanel

Supriya said...

this cretes at compile time i.e.at using this app.u cant create new Checkboxes.
can u tell me the that using app same time i should able to create new checjboxes as well as put it onto JPanel