Java JCheckBox set selected to true

Description

Java JCheckBox set selected to true

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

public class Main {
  public static void main(String args[]) {
    JFrame frame = new JFrame("CheckBox");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JCheckBox checkbox = new JCheckBox("CSS");
    // Get the current state of the checkbox
    boolean b = checkbox.isSelected();

    // Set the state of the checkbox to off
    checkbox.setSelected(false);//from  w  w w.ja va  2s  .c om

    // Set the state of the checkbox to on
    checkbox.setSelected(true);

    frame.add(checkbox);
    frame.setSize(300, 200);
    frame.setVisible(true);
  }
}



PreviousNext

Related