- 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 can we set a border to JCheckBox in Java?
A JCheckBox is a component that can extend JToggleButton and an object of JCheckBox represents an option that can be checked or unchecked. If there are two or more options then any combination of these options can be selected at the same time. We can set a border to the JCheckBox component by using the setBorder() method and make sure that setBorderPainted() method set to true.
Example
import java.awt.*; import java.awt.event.*; import javax.swing.*; public class BorderedJCheckBoxTest extends JFrame { private JCheckBox jcb; public BorderedJCheckBoxTest() throws Exception { setTitle("JCheckBox Test"); setLayout(new FlowLayout()); jcb = new JCheckBox("BorderedJCheckBox Test"); jcb.setBorderPainted(true); jcb.setBorder(BorderFactory.createLineBorder(Color.red)); // set the border add(jcb); setSize(375, 250); setLocationRelativeTo(null); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); } public static void main(String args[]) throws Exception { new BorderedJCheckBoxTest(); } }
Output
- Related Articles
- How can we set the border to JComboBox items in Java?
- How can we add/insert a JCheckBox inside a JTable cell in Java?
- How to set the shortcut key to a JCheckBox in Java?
- How to set tooltip text for JCheckBox in Java?
- How can we convert list to Set in Java?
- How to get or set the selection state of JCheckBox in Java
- How to set Mnemonic key for selection of each JCheckBox in Java?
- How can we set the margin to a JButton in Java?
- How can we set a background color to JSplitPane in Java?
- How can we sort a JSONObject in Java?\n
- Can we convert a list to a Set in Java?
- How can we set the background color to a JPanel in Java?
- How can we set the shortcut key to a JButton in Java?
- How can we create a login form in Java?\n
- How can we initialize a boolean array in Java?\n

Advertisements