- 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 display a JRadioButtonMenuItem in Java?n
A JRadioButtonMenuItem is a subclass of the JMenuItem class in Java. A JRadioButtonMenuItem is a menu item that is part of a group of menu items in which only one item in the group can be selected and the selected item displays its selected state. We can add multiple radio button menu items to a ButtonGroup object to form a button group. If one radio button menu item in a button group is selected, all other radio button menu items will be unselected.
Syntax
public class JRadioButtonMenuItem extends JMenuItem implements Accessible
Example
import javax.swing.*; import java.awt.*; public class JRadioButtonMenuItemTest extends JFrame { private JMenuBar mb; private JMenu m; private JRadioButtonMenuItem m1, m2, m3, m4; private ButtonGroup bg; public JRadioButtonMenuItemTest() { setTitle("JRadioButtonMenuItem Test"); setLayout(new FlowLayout()); bg = new ButtonGroup(); mb = new JMenuBar(); m = new JMenu("Menu"); m1 = new JRadioButtonMenuItem(); m2 = new JRadioButtonMenuItem(new javax.swing.text.DefaultEditorKit.BeepAction()); m3 = new JRadioButtonMenuItem("Item 3"); m4 = new JRadioButtonMenuItem("Item 4",true); m1.setText("Item 1"); m1.setFont(new Font("Tahoma",Font.PLAIN,11)); m1.setSelected(true); m2.setAccelerator(KeyStroke.getKeyStroke("ctrl 2")); m3.setEnabled(false); bg.add(m1); bg.add(m2); bg.add(m3); bg.add(m4); m.add(m1); m.add(m2); m.add(m3); m.add(m4); mb.add(m); setJMenuBar(mb); setSize(400, 300); setDefaultCloseOperation(EXIT_ON_CLOSE); setLocationRelativeTo(null); setVisible(true); } public static void main(String args[]) { new JRadioButtonMenuItemTest(); } }
Output
- Related Articles
- How to add JRadioButtonMenuItem in Java
- How to display a large component within a smaller display area in Java?
- How to display the items in a JComboBox in Java
- How to display the first element in a JComboBox in Java
- How to display a JFrame to the center of a screen in Java?
- How to display tree structured data in Java?
- How to display a value when select a JList item in Java?
- How to hide and display JCombobox with a JCheckBox in Java?
- How to display horizontal grid lines in a JTable with Java?
- How to display vertical grid lines in a table with Java?
- How to display numbers in scientific notation in Java?
- Display a percentage in Java
- Java Program to display a webpage in JEditorPane
- How to display a bold text inside the JTextArea in Java?\n
- How to display the different font items inside a JComboBox in Java?

Advertisements