JCheckBox




The JCheckBox class allows you to display a message and a check box.
You must add an import statement:
import javax.swing.JCheckBox;
JCheckBox is a component or widget. You add components to a container, like a JPanel.

Examples:


// creates an unchecked JCheckBox
JCheckBox myCheckBox = new JCheckBox("Use WIFI");
myCheckBox.setFont(new Font("Courier", Font.PLAIN, 32));

// creates an checked JCheckBox
JCheckBox myCheckBox = new JCheckBox("Use WIFI",true);




Other Common Methods:

boolean myStatus = myCheckBox.isSelected();

myCheckBox.setSelected(true);  // adds check mark

Note: You can also add an ItemListener or an ActionListener.