JCheckBox is a widget that has two states. On and Off. : CheckBox Button « Swing JFC « Java






JCheckBox is a widget that has two states. On and Off.

  

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JCheckBox;
import javax.swing.JFrame;

public class CheckBox extends JFrame implements ActionListener {

  public CheckBox() {
    JCheckBox checkbox = new JCheckBox("Show Title", true);
    checkbox.addActionListener(this);
    add(checkbox);

    setSize(280, 200);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setVisible(true);
  }

  public static void main(String[] args) {
    new CheckBox();
  }

  public void actionPerformed(ActionEvent e) {
    if (this.getTitle() == "") {
      this.setTitle("Checkbox example");
    } else {
      this.setTitle("");
    }
  }
}

   
    
  








Related examples in the same category

1.Swing CheckBoxesSwing CheckBoxes
2.CheckBox Demo 2CheckBox Demo 2
3. How to use the check box button How to use the check box button
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