Java Swing Program to demonstrate JCheckBox with Text
Program
import javax.swing.*;
public class JCheckBoxDemo
{
public static void main(String[] args)
{
JFrame frm = new JFrame("JCheckBox Demo");
JCheckBox chkbxMilk = new JCheckBox();
chkbxMilk.setText("Milk");
chkbxMilk.setSelected(true);
chkbxMilk.setBounds(0, 0, 100, 50);
JCheckBox chkbxCoffee = new JCheckBox();
chkbxCoffee.setText("Coffee");
chkbxCoffee.setBounds(0, 50, 100, 50);
JCheckBox chkbxTea = new JCheckBox();
chkbxTea.setText("Tea");
chkbxTea.setBounds(0, 100, 100, 50);
frm.add(chkbxMilk);
frm.add(chkbxCoffee);
frm.add(chkbxTea);
frm.setSize(300, 300);
frm.setLayout(null);
frm.setVisible(true);
frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
Output