- Trending Categories
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 get or set the selection state of JCheckBox in Java
The following is an example to get or set the selection state of JCheckBox:
Example
import java.awt.FlowLayout; import javax.swing.JCheckBox; import javax.swing.JFrame; public class SwingDemo extends JFrame { public SwingDemo() { setSize(500, 500); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLayout(new FlowLayout(FlowLayout.CENTER)); JCheckBox checkBox = new JCheckBox("Demo"); checkBox.setSelected(true); boolean sel = checkBox.isSelected(); if (sel) System.out.println("Check box selected!"); getContentPane().add(checkBox); } public static void main(String[] args) { new SwingDemo().setVisible(true); } }
Output
Since the checkbox is selected by default, the following output would be visible in EclipseIDE:
- Related Articles
- How to set Mnemonic key for selection of each JCheckBox in Java?
- How to set tooltip text for JCheckBox in Java?
- How to set the shortcut key to a JCheckBox in Java?
- How can we set a border to JCheckBox in Java?\n
- Java Program to set Selection Mode for JList only for single selection
- How to disable JCheckBox if not checked in Java
- PHP – How to get or set the path of a domain?
- How to get the style of current selection in Text using FabricJS?
- Can we set JOptionPane with predefined selection in Java?
- How to set the background color of selection of Ellipse using FabricJS?
- How to set the background colour of selection of Rectangle using FabricJS?
- How to set the background colour of selection of Textbox using FabricJS?
- FabricJS – How to set the background colour of selection of an Image?
- How to hide and display JCombobox with a JCheckBox in Java?
- How to set the background colour of selection of a Triangle using FabricJS?

Advertisements