How to use the check box button : CheckBox Button « Swing JFC « Java

How to use the check box button

 How to use the check box button
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class CheckBoxDemo extends JFrame implements ActionListener {

  JLabel fontLabel = new JLabel("The quick brown fox jumps over the lazy dog.");

  private JCheckBox bold= new JCheckBox("Bold");

  private JCheckBox italic = new JCheckBox("Italic");

  public CheckBoxDemo() {
    setSize(300, 200);
    addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) {

    JPanel p = new JPanel();
    getContentPane().add(p, "South");
    getContentPane().add(fontLabel, "Center");

  public void actionPerformed(ActionEvent evt) {
    int m = (bold.isSelected() ? Font.BOLD : 0)
        + (italic.isSelected() ? Font.ITALIC : 0);
    fontLabel.setFont(new Font("SansSerif", m, 12));
  public static void main(String[] args) {
    JFrame frame = new CheckBoxDemo();;


Related examples in the same category

1.JCheckBox is a widget that has two states. On and Off.
2.Swing CheckBoxesSwing CheckBoxes
3.CheckBox Demo 2CheckBox Demo 2
4.CheckBox MnemonicCheckBox Mnemonic
5.Bad Checkbox UIBad Checkbox UI
6.React to menu action and checkbox menuReact to menu action and checkbox menu
7.Swing CheckBox DemoSwing CheckBox Demo
8.CheckBox Item ListenerCheckBox Item Listener
9.Icon CheckBox DemoIcon CheckBox Demo
10.Flat CheckBoxFlat CheckBox
11.Customizing the Icons in a JCheckBox Component
12.Customize these disabled icons
13.Set pressed icon
14.Display an icon when the cursor is moved over the checkbox. This is called the rollover icon.
15.Adding an Icon to the Label of a JCheckBox Component
16.Getting and Setting the State of a JCheckbox Component
17.Creating a JCheckbox Component
18.Check boxes with item changed event.
19.Get or set the selection state of JCheckBox
20.Customize JCheckBox icons
21.Radio button, ComboBoxRadio button, ComboBox
22.Using CheckBox ActionListener to controll font