- 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
Advertisements