Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

1 Answer
Krantik Chavan

The following is an example to disable JCheckBox if not checked in Java:

Example

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JCheckBox;
import javax.swing.JOptionPane;
public class SwingDemo {
   public static void main(String[] args) {
      JCheckBox checkBox = new JCheckBox("Demo", true);
      checkBox.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent e) {
            if (checkBox.isEnabled())
               checkBox.setEnabled(false);
            else
               checkBox.setEnabled(true);
         }
      });
      JOptionPane.showMessageDialog(null, checkBox);
   }
}

Output

Now, when you will uncheck the above checkbox, it will get disabled:

Advertisements

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.