- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
Java Program to create JCheckBox from text in Swing
The following is an example to create JCheckBox from text in Swing:
Example
import java.awt.FlowLayout; import javax.swing.JCheckBox; import javax.swing.JFrame; import javax.swing.JLabel; public class SwingDemo { public static void main(String[] args) { JCheckBox checkBox1 = new JCheckBox("Cricket"); JCheckBox checkBox2 = new JCheckBox("Squash"); JCheckBox checkBox3 = new JCheckBox("Football"); checkBox3.setSelected(true); JCheckBox checkBox4 = new JCheckBox("Hockey"); JCheckBox checkBox5 = new JCheckBox("Fencing"); JCheckBox checkBox6 = new JCheckBox("Tennis"); JFrame frame = new JFrame(); frame.setLayout(new FlowLayout()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(new JLabel("Fav Sports? ")); frame.add(checkBox1); frame.add(checkBox2); frame.add(checkBox3); frame.add(checkBox4); frame.add(checkBox5); frame.add(checkBox6); frame.pack(); frame.setVisible(true); } }
Output
- Related Articles
- Java Program to create rounded borders in Swing
- Java Program to create JRadioButton from text
- How to set tooltip text for JCheckBox in Java?
- Create translucent windows in Java Swing
- Create shaped windows in Java Swing
- Create Toast Message in Java Swing\n
- Create gradient translucent windows in Java Swing
- I want to highlight all the text in the Java Swing Control Text Pane
- Create a simple calculator using Java Swing
- How to create a Default Cell Editor that uses a JCheckBox in Java?
- Java Program to use Soft Bevel Border in Swing
- Java Program to add Titled Border to Panel in Swing
- Java Program to append a row to a JTable in Java Swing
- How to select one item at a time from JCheckBox in Java?
- Program to combine BorderLayout, GridLayout and FlowLayout in Java Swing?

Advertisements