Swing JRadioButton

In this tutorial you will learn about the Swing JRadioButton and its application with practical example.

Swing JRadioButton

The JRadioButton class is used to create radio button. It’s an implementation of a radio button. This radio button are used for selecting one option from multiple choice. Used with a ButtonGroup object to create a group of button in which only one button at a time can be selected.

JRadioButton Class Declaration

JRadioButton Constructor

Let’s get more understand about JRadioButton, Some of important constructor are listed below.

JRadioButton () : This constructor construct a new radio button with unselected state and no text , no icon.

JRadioButton (String text): This constructor construct a new radio button with unselected state and with text.

JRadioButton (Icon icon): This constructor construct a new radio button with unselected state and with icon.

JRadioButton (String text, boolean selected): This constructor construct a new radio button with text and specify whether or not it is initially selected.

JRadioButton (String text, Icon icon): This constructor is used to construct a new radio button with text and with icon.

JRadioButton (String text, Icon icon, boolean selected): This constructor is used to construct a new radio button with text, icon and specify whether or not it is initially selected.

JRadioButton (Action a): Construct a radio button where properties are taken from the Action supplied.

JRadioButton Methods

Some of commonly used methods are listed below. It will help to know more about JRadioButton.

AccessibleContext getAccessibleContext(): Used to gets the AccessibleContext which is associated with this JRadioButton.

void updateUI(): This method is used to resets the UI property to a value from the current look and feel.

Recommended:-  Swing JFrame

protected String paramString(): This method returns string representation of this JRadioButton.

Example :-

An simple example to get understand about JRadioButton. Hopefully this will work for you.

Output :-

Output of this code will look like below image. You just need to copy this code and paste it in you program.

Recommended:-  Swing JProgessBar

image001

In this tutorial we have learn about the Swing JRadioButton and its application with practical example. I hope you will like this tutorial.