Mega Code Archive

 
Categories / Java Tutorial / Swing
 

Getting and Setting the State of a JCheckbox Component

import javax.swing.JCheckBox; public class Main {   public static void main(String[] argv) throws Exception {     JCheckBox checkbox = new JCheckBox();     // Get the current state of the checkbox     boolean b = checkbox.isSelected();     // Set the state of the checkbox to off     checkbox.setSelected(false);     // Set the state of the checkbox to on     checkbox.setSelected(true);   } }