javax.swing

Class JRadioButton

public class JRadioButton extends JToggleButton

The JRadioButton component provides a visually selectable button with mutually exclusive behaviour within a ButtonGroup. A series of radio buttons can be used to provide options to the user, where the user can only select one of the available options. The state of the button is provided by the superclass, JToggleButton. JRadioButton adds the additional behaviour, that if two or more radio buttons are grouped together, the selection of one implies the deselection of the other buttons within the group.

Buttons are grouped by adding each instance to a ButtonGroup. The existence of such a grouping is not reflected visually, so other means should be used to denote this. For instance, the grouped buttons can be placed within the same panel, possibly with an appropriate border to denote the connection between the components.

Since: 1.2

See Also: JToggleButton ButtonGroup

Nested Class Summary
protected classJRadioButton.AccessibleJRadioButton
This class provides accessibility support for the toggle button.
Constructor Summary
JRadioButton()
Constructs an unselected radio button with no text or icon.
JRadioButton(Action a)
Constructs a radio button using the labelling, state and icon specified by the supplied action.
JRadioButton(Icon icon)
Constructs an unselected radio button with the supplied icon and no text.
JRadioButton(Icon icon, boolean selected)
Constructs a radio button with the supplied icon and state.
JRadioButton(String text)
Constructs an unselected radio button using the supplied text and no icon.
JRadioButton(String text, boolean selected)
Constructs a radio button with the supplied text and state.
JRadioButton(String text, Icon icon)
Constructs an unselected radio button with the supplied text and icon.
JRadioButton(String text, Icon icon, boolean selected)
Constructs a radio button with the supplied text, icon and state.
Method Summary
AccessibleContextgetAccessibleContext()
Returns the accessible context for this JRadioButton, in the form of an instance of AccessibleJRadioButton.
StringgetUIClassID()
Returns a string specifying the name of the Look and Feel UI class that renders this component.
protected StringparamString()
Returns a string representation of this component for debugging use.
voidupdateUI()
This method resets the radio button's UI delegate to the default UI for the current look and feel.

Constructor Detail

JRadioButton

public JRadioButton()
Constructs an unselected radio button with no text or icon.

JRadioButton

public JRadioButton(Action a)
Constructs a radio button using the labelling, state and icon specified by the supplied action.

Parameters: a the action to use to define the properties of the button.

JRadioButton

public JRadioButton(Icon icon)
Constructs an unselected radio button with the supplied icon and no text.

Parameters: icon the icon to use.

JRadioButton

public JRadioButton(Icon icon, boolean selected)
Constructs a radio button with the supplied icon and state.

Parameters: icon the icon to use. selected if true, the radio button is initially in the selected state. Otherwise, the button is unselected.

JRadioButton

public JRadioButton(String text)
Constructs an unselected radio button using the supplied text and no icon.

Parameters: text the text to use.

JRadioButton

public JRadioButton(String text, boolean selected)
Constructs a radio button with the supplied text and state.

Parameters: text the text to use. selected if true, the radio button is initially in the selected state. Otherwise, the button is unselected.

JRadioButton

public JRadioButton(String text, Icon icon)
Constructs an unselected radio button with the supplied text and icon.

Parameters: text the text to use. icon the icon to use.

JRadioButton

public JRadioButton(String text, Icon icon, boolean selected)
Constructs a radio button with the supplied text, icon and state.

Parameters: text the text to use. icon the icon to use. selected if true, the radio button is initially in the selected state. Otherwise, the button is unselected.

Method Detail

getAccessibleContext

public AccessibleContext getAccessibleContext()
Returns the accessible context for this JRadioButton, in the form of an instance of AccessibleJRadioButton. The context is created, if necessary.

Returns: the associated context

getUIClassID

public String getUIClassID()
Returns a string specifying the name of the Look and Feel UI class that renders this component.

Returns: the Look and Feel UI class for JRadioButtons as a String.

paramString

protected String paramString()
Returns a string representation of this component for debugging use. Users should not depend on anything as regards the content or formatting of this string, except for the fact that the returned string may never be null (only empty).

Returns: the component in String form for debugging.

updateUI

public void updateUI()
This method resets the radio button's UI delegate to the default UI for the current look and feel.