- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to disable JCheckBox if not checked in Java
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
To Continue Learning Please Login
Login with Google