In this section, you will learn how to create a radio button in java swing. Radio Button is like check box. Differences between check box and radio button are as follows:
Here, you will see the JRadioButton component creation procedure in java with the help of this program. This example provides two radio buttons same ButtonGroup. These radio buttons represent the option for choosing male or female. Following is the image for the result of the given program:
The creation of JRadioButton are completed by the following methods:
This is the class of the javax.swing.*; package, which is used to create a group of radio buttons from which you can select only one option from that group of the radio buttons. This is class is used by creating a instance of if using it's constructor. Radio Buttons are added to the specified group using the add(JRadioButton) method of the ButtonGroup class.
This is the class has been used to create a single radio button for the application.
This method sets the value of the radio button. This method takes a boolean value either true or false. If you pass true value then the radio button will be selected otherwise the radio button is not selected.
Here is the code of program:
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.