- 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
Java Program to create JRadioButton from text
The following is an example to create JRadioButton from text −
Example
package my; import java.awt.FlowLayout; import java.awt.event.KeyEvent; import javax.swing.ButtonGroup; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JRadioButton; public class SwingDemo { public static void main(String[] args) { JRadioButton radio1 = new JRadioButton("Cricket"); JRadioButton radio2 = new JRadioButton("Football"); ButtonGroup group = new ButtonGroup(); group.add(radio1); group.add(radio2); radio1.setSelected(true); JFrame frame = new JFrame(); frame.setLayout(new FlowLayout()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(new JLabel("Fav Sports:")); frame.add(radio1); frame.add(radio2); frame.pack(); frame.setVisible(true); } }
Output
- Related Articles
- Java Program to create JCheckBox from text in Swing
- Java Program to create Duration from seconds
- Java Program to create LocalDateTime from Clock
- Java program to delete certain text from a file
- Java Program to create a boolean variable from string
- Java Program to create Character Array from String Objects
- Java Program to create DefaultTableModel from two dimensional array
- Java Program to get text from JTextPane and display in Console
- Java Program to Create String from Contents of a File
- Java Program to create Instant from Epoch second and millisecond
- Java Program to create Stream from a String/Byte Array
- What are the differences between JRadioButton and JCheckBox in Java?
- How to create a Python dictionary from text file?
- Java Program to create a BigDecimal from a string type value
- Java Program to format text in JTextPane

Advertisements