APIdia Launch Partner
Top Description Inners Fields Constructors Methods
javax.swing

public Class JRadioButton

extends JToggleButton
implements Accessible
Class Inheritance
All Implemented Interfaces
javax.accessibility.Accessible
Annotations
@JavaBean
description:A component which can display it\'s state as selected or deselected.
@SwingContainer:false
@SuppressWarnings:serial
Imports
java.beans.BeanProperty, .JavaBean, java.io.IOException, .ObjectOutputStream, .Serial, javax.accessibility.Accessible, .AccessibleContext, .AccessibleRole, javax.swing.plaf.ButtonUI

An implementation of a radio button -- an item that can be selected or deselected, and which displays its state to the user. Used with a ButtonGroup object to create a group of buttons in which only one button at a time can be selected. (Create a ButtonGroup object and use its add method to include the JRadioButton objects in the group.)

Note

The ButtonGroup object is a logical grouping -- not a physical grouping. To create a button panel, you should still create a JPanel or similar container-object and add a javax.swing.border.Border to it to set it off from surrounding components.

Buttons can be configured, and to some degree controlled, by Actions. Using an Action with a button has many benefits beyond directly configuring a button. Refer to Swing Components Supporting Action for more details, and you can find more information in How to Use Actions, a section in The Java Tutorial.

See How to Use Buttons, Check Boxes, and Radio Buttons in The Java Tutorial for further documentation.

Warning

Swing is not thread safe. For more information see Swing's Threading Policy.

Warning

Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeans has been added to the java.beans package. Please see java.beans.XMLEncoder.

Author
Jeff Dinkins
Since
1.2
See Also
ButtonGroup, JCheckBox

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected class
JRadioButton.AccessibleJRadioButton

This class implements accessibility support for the JRadioButton class.

Field Summary

Modifier and TypeField and Description
private static final String

Constructor Summary

AccessConstructor and Description
public
JRadioButton()

Creates an initially unselected radio button with no set text.

public
JRadioButton(Icon
the image that the button should display
icon
)

Creates an initially unselected radio button with the specified image but no text.

public
JRadioButton(Action
an Action
a
)

Creates a radiobutton where properties are taken from the Action supplied.

public
JRadioButton(Icon
the image that the button should display
icon
,
boolean
if true, the button is initially selected; otherwise, the button is initially unselected
selected
)

Creates a radio button with the specified image and selection state, but no text.

public
JRadioButton(String
the string displayed on the radio button
text
)

Creates an unselected radio button with the specified text.

public
JRadioButton(String
the string displayed on the radio button
text
,
boolean
if true, the button is initially selected; otherwise, the button is initially unselected
selected
)

Creates a radio button with the specified text and selection state.

public
JRadioButton(String
the string displayed on the radio button
text
,
Icon
the image that the button should display
icon
)

Creates a radio button that has the specified text and image, and that is initially unselected.

public
JRadioButton(String
the string displayed on the radio button
text
,
Icon
the image that the button should display
icon
,
boolean
if true, the button is initially selected otherwise, the button is initially unselected
selected
)

Creates a radio button that has the specified text, image, and selection state.

Method Summary

Modifier and TypeMethod and Description
public AccessibleContext

Returns:

an AccessibleJRadioButton that serves as the AccessibleContext of this JRadioButton
getAccessibleContext
()

Overrides javax.swing.JToggleButton.getAccessibleContext.

Implements javax.accessibility.Accessible.getAccessibleContext.

Gets the AccessibleContext associated with this JRadioButton.

public String

Returns:

the string "RadioButtonUI"
getUIClassID
()

Overrides javax.swing.JToggleButton.getUIClassID.

Returns the name of the L&F class that renders this component.

protected String

Returns:

a string representation of this JRadioButton.
paramString
()

Overrides javax.swing.JToggleButton.paramString.

Returns a string representation of this JRadioButton.

pack-priv void
setIconFromAction(Action a)

Overrides javax.swing.AbstractButton.setIconFromAction.

The icon for radio buttons comes from the look and feel, not the Action.

public void
updateUI()

Overrides javax.swing.JToggleButton.updateUI.

Resets the UI property to a value from the current look and feel.

private void
writeObject(ObjectOutputStream s)

Hides javax.swing.JToggleButton.writeObject.

See readObject() and writeObject() in JComponent for more information about serialization in Swing.

Inherited from javax.swing.JToggleButton:
requestFocusrequestFocusInWindowshouldUpdateSelectedStateFromAction

Field Detail

uiClassIDback to summary
private static final String uiClassID

Hides javax.swing.JToggleButton.uiClassID.

See Also
getUIClassID, readObject

Constructor Detail

JRadioButtonback to summary
public JRadioButton()

Creates an initially unselected radio button with no set text.

JRadioButtonback to summary
public JRadioButton(Icon icon)

Creates an initially unselected radio button with the specified image but no text.

Parameters
icon:Icon

the image that the button should display

JRadioButtonback to summary
public JRadioButton(Action a)

Creates a radiobutton where properties are taken from the Action supplied.

Parameters
a:Action

an Action

Since
1.3
JRadioButtonback to summary
public JRadioButton(Icon icon, boolean selected)

Creates a radio button with the specified image and selection state, but no text.

Parameters
icon:Icon

the image that the button should display

selected:boolean

if true, the button is initially selected; otherwise, the button is initially unselected

JRadioButtonback to summary
public JRadioButton(String text)

Creates an unselected radio button with the specified text.

Parameters
text:String

the string displayed on the radio button

JRadioButtonback to summary
public JRadioButton(String text, boolean selected)

Creates a radio button with the specified text and selection state.

Parameters
text:String

the string displayed on the radio button

selected:boolean

if true, the button is initially selected; otherwise, the button is initially unselected

JRadioButtonback to summary
public JRadioButton(String text, Icon icon)

Creates a radio button that has the specified text and image, and that is initially unselected.

Parameters
text:String

the string displayed on the radio button

icon:Icon

the image that the button should display

JRadioButtonback to summary
public JRadioButton(String text, Icon icon, boolean selected)

Creates a radio button that has the specified text, image, and selection state.

Parameters
text:String

the string displayed on the radio button

icon:Icon

the image that the button should display

selected:boolean

if true, the button is initially selected otherwise, the button is initially unselected

Method Detail

getAccessibleContextback to summary
public AccessibleContext getAccessibleContext()

Overrides javax.swing.JToggleButton.getAccessibleContext.

Implements javax.accessibility.Accessible.getAccessibleContext.

Gets the AccessibleContext associated with this JRadioButton. For JRadioButtons, the AccessibleContext takes the form of an AccessibleJRadioButton. A new AccessibleJRadioButton instance is created if necessary.

Returns:AccessibleContext

an AccessibleJRadioButton that serves as the AccessibleContext of this JRadioButton

Annotations
@BeanProperty
bound:false
expert:true
description:The AccessibleContext associated with this Button
getUIClassIDback to summary
public String getUIClassID()

Overrides javax.swing.JToggleButton.getUIClassID.

Returns the name of the L&F class that renders this component.

Returns:String

the string "RadioButtonUI"

Annotations
@BeanProperty
bound:false
expert:true
description:A string that specifies the name of the L&F class.
See Also
JComponent#getUIClassID, UIDefaults#getUI
paramStringback to summary
protected String paramString()

Overrides javax.swing.JToggleButton.paramString.

Returns a string representation of this JRadioButton. This method is intended to be used only for debugging purposes, and the content and format of the returned string may vary between implementations. The returned string may be empty but may not be null.

Returns:String

a string representation of this JRadioButton.

setIconFromActionback to summary
pack-priv void setIconFromAction(Action a)

Overrides javax.swing.AbstractButton.setIconFromAction.

The icon for radio buttons comes from the look and feel, not the Action.

updateUIback to summary
public void updateUI()

Overrides javax.swing.JToggleButton.updateUI.

Resets the UI property to a value from the current look and feel.

See Also
JComponent#updateUI
writeObjectback to summary
private void writeObject(ObjectOutputStream s) throws IOException

Hides javax.swing.JToggleButton.writeObject.

See readObject() and writeObject() in JComponent for more information about serialization in Swing.

Annotations
@Serial
Exceptions
IOException:

Doc from java.awt.Container.writeObject.

if an I/O error occurs

javax.swing back to summary

protected Class JRadioButton.AccessibleJRadioButton

extends AccessibleJToggleButton
Class Inheritance
Annotations
@SuppressWarnings:serial

This class implements accessibility support for the JRadioButton class. It provides an implementation of the Java Accessibility API appropriate to radio button user-interface elements.

Warning

Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeans has been added to the java.beans package. Please see java.beans.XMLEncoder.

Constructor Summary

AccessConstructor and Description
protected
AccessibleJRadioButton()

Constructs an AccessibleJRadioButton.

Method Summary

Modifier and TypeMethod and Description
public AccessibleRole

Returns:

an instance of AccessibleRole describing the role of the object
getAccessibleRole
()

Overrides javax.swing.JToggleButton.AccessibleJToggleButton.getAccessibleRole.

Get the role of this object.

Inherited from javax.swing.JToggleButton.AccessibleJToggleButton:
itemStateChanged

Constructor Detail

AccessibleJRadioButtonback to summary
protected AccessibleJRadioButton()

Constructs an AccessibleJRadioButton.

Method Detail

getAccessibleRoleback to summary
public AccessibleRole getAccessibleRole()

Overrides javax.swing.JToggleButton.AccessibleJToggleButton.getAccessibleRole.

Get the role of this object.

Returns:AccessibleRole

an instance of AccessibleRole describing the role of the object

See Also
AccessibleRole