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

public Class JRadioButtonMenuItem

extends JMenuItem
implements Accessible
Class Inheritance
All Implemented Interfaces
javax.accessibility.Accessible
Annotations
@JavaBean
description:A component within a group of menu items which can be selected.
@SwingContainer:false
@SuppressWarnings:serial
Imports
java.beans.BeanProperty, .JavaBean, java.io.IOException, .ObjectOutputStream, .Serial, javax.accessibility.Accessible, .AccessibleContext, .AccessibleRole

An implementation of a radio button menu item. 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. The selected item displays its selected state. Selecting it causes any other selected item to switch to the unselected state. To control the selected state of a group of radio button menu items, use a ButtonGroup object.

Menu items can be configured, and to some degree controlled, by Actions. Using an Action with a menu item has many benefits beyond directly configuring a menu item. 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.

Some menus can have several button groups with radio button menu items. In this case it is useful that clicking on one radio button menu item does not close the menu. Such behavior can be controlled either by client JComponent#putClientProperty or the Look and Feel UIManager#put property named "RadioButtonMenuItem.doNotCloseOnMouseClick". The default value is false. Setting the property to true prevents the menu from closing when it is clicked by the mouse. If the client property is set its value is always used; otherwise the L&F property is queried.

Note

some L&Fs may ignore this property. All built-in L&Fs inherit this behaviour.

For further documentation and examples see How to Use Menus, a section in The Java Tutorial.

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.

Authors
Georges Saab, David Karlton
Since
1.2
See Also
ButtonGroup

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected class
JRadioButtonMenuItem.AccessibleJRadioButtonMenuItem

This class implements accessibility support for the JRadioButtonMenuItem class.

Field Summary

Modifier and TypeField and Description
private static final String

Constructor Summary

AccessConstructor and Description
public
JRadioButtonMenuItem()

Creates a JRadioButtonMenuItem with no set text or icon.

public
JRadioButtonMenuItem(Icon
the Icon to display on the JRadioButtonMenuItem
icon
)

Creates a JRadioButtonMenuItem with an icon.

public
JRadioButtonMenuItem(String
the text of the JRadioButtonMenuItem
text
)

Creates a JRadioButtonMenuItem with text.

public
JRadioButtonMenuItem(Action
the Action on which to base the radio button menu item
a
)

Creates a radio button menu item whose properties are taken from the Action supplied.

public
JRadioButtonMenuItem(String
the text of the JRadioButtonMenuItem
text
,
Icon
the icon to display on the JRadioButtonMenuItem
icon
)

Creates a radio button menu item with the specified text and Icon.

public
JRadioButtonMenuItem(String
the text of the CheckBoxMenuItem
text
,
boolean
the selected state of the CheckBoxMenuItem
selected
)

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

public
JRadioButtonMenuItem(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 menu item with the specified image and selection state, but no text.

public
JRadioButtonMenuItem(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 menu item that has the specified text, image, and selection state.

Method Summary

Modifier and TypeMethod and Description
public AccessibleContext

Returns:

an AccessibleJRadioButtonMenuItem that serves as the AccessibleContext of this JRadioButtonMenuItem
getAccessibleContext
()

Overrides javax.swing.JMenuItem.getAccessibleContext.

Implements javax.accessibility.Accessible.getAccessibleContext.

Gets the AccessibleContext associated with this JRadioButtonMenuItem.

public String

Returns:

the string "RadioButtonMenuItemUI"
getUIClassID
()

Overrides javax.swing.JMenuItem.getUIClassID.

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

protected String

Returns:

a string representation of this JRadioButtonMenuItem
paramString
()

Overrides javax.swing.JMenuItem.paramString.

Returns a string representation of this JRadioButtonMenuItem.

pack-priv boolean
shouldUpdateSelectedStateFromAction()

Overrides javax.swing.AbstractButton.shouldUpdateSelectedStateFromAction.

Overridden to return true, JRadioButtonMenuItem supports the selected state.

private void
writeObject(ObjectOutputStream s)

Hides javax.swing.JMenuItem.writeObject.

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

Inherited from javax.swing.JMenuItem:
actionPropertyChangedaddMenuDragMouseListeneraddMenuKeyListeneralwaysOnTopconfigureAcceleratorFromActionconfigurePropertiesFromActionfireMenuDragMouseDraggedfireMenuDragMouseEnteredfireMenuDragMouseExitedfireMenuDragMouseReleasedfireMenuKeyPressedfireMenuKeyReleasedfireMenuKeyTypedgetAcceleratorgetComponentgetMenuDragMouseListenersgetMenuKeyListenersgetSubElementsinitinitFocusabilityisArmedlargeIconChangedmenuSelectionChangedprocessKeyEventprocessMenuDragMouseEventprocessMenuKeyEventprocessMouseEventremoveMenuDragMouseListenerremoveMenuKeyListenersetAcceleratorsetArmedsetEnabledsetIconFromActionsetModelsetUIsmallIconChangedupdateUI

Field Detail

uiClassIDback to summary
private static final String uiClassID

Hides javax.swing.JMenuItem.uiClassID.

See Also
getUIClassID, readObject

Constructor Detail

JRadioButtonMenuItemback to summary
public JRadioButtonMenuItem()

Creates a JRadioButtonMenuItem with no set text or icon.

JRadioButtonMenuItemback to summary
public JRadioButtonMenuItem(Icon icon)

Creates a JRadioButtonMenuItem with an icon.

Parameters
icon:Icon

the Icon to display on the JRadioButtonMenuItem

JRadioButtonMenuItemback to summary
public JRadioButtonMenuItem(String text)

Creates a JRadioButtonMenuItem with text.

Parameters
text:String

the text of the JRadioButtonMenuItem

JRadioButtonMenuItemback to summary
public JRadioButtonMenuItem(Action a)

Creates a radio button menu item whose properties are taken from the Action supplied.

Parameters
a:Action

the Action on which to base the radio button menu item

Since
1.3
JRadioButtonMenuItemback to summary
public JRadioButtonMenuItem(String text, Icon icon)

Creates a radio button menu item with the specified text and Icon.

Parameters
text:String

the text of the JRadioButtonMenuItem

icon:Icon

the icon to display on the JRadioButtonMenuItem

JRadioButtonMenuItemback to summary
public JRadioButtonMenuItem(String text, boolean selected)

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

Parameters
text:String

the text of the CheckBoxMenuItem

selected:boolean

the selected state of the CheckBoxMenuItem

JRadioButtonMenuItemback to summary
public JRadioButtonMenuItem(Icon icon, boolean selected)

Creates a radio button menu item 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

JRadioButtonMenuItemback to summary
public JRadioButtonMenuItem(String text, Icon icon, boolean selected)

Creates a radio button menu item that has the specified text, image, and selection state. All other constructors defer to this one.

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.JMenuItem.getAccessibleContext.

Implements javax.accessibility.Accessible.getAccessibleContext.

Gets the AccessibleContext associated with this JRadioButtonMenuItem. For JRadioButtonMenuItems, the AccessibleContext takes the form of an AccessibleJRadioButtonMenuItem. A new AccessibleJRadioButtonMenuItem instance is created if necessary.

Returns:AccessibleContext

an AccessibleJRadioButtonMenuItem that serves as the AccessibleContext of this JRadioButtonMenuItem

Annotations
@BeanProperty
bound:false
getUIClassIDback to summary
public String getUIClassID()

Overrides javax.swing.JMenuItem.getUIClassID.

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

Returns:String

the string "RadioButtonMenuItemUI"

Annotations
@BeanProperty
bound:false
See Also
JComponent#getUIClassID, UIDefaults#getUI
paramStringback to summary
protected String paramString()

Overrides javax.swing.JMenuItem.paramString.

Returns a string representation of this JRadioButtonMenuItem. 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 JRadioButtonMenuItem

shouldUpdateSelectedStateFromActionback to summary
pack-priv boolean shouldUpdateSelectedStateFromAction()

Overrides javax.swing.AbstractButton.shouldUpdateSelectedStateFromAction.

Overridden to return true, JRadioButtonMenuItem supports the selected state.

writeObjectback to summary
private void writeObject(ObjectOutputStream s) throws IOException

Hides javax.swing.JMenuItem.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 JRadioButtonMenuItem.AccessibleJRadioButtonMenuItem

extends AccessibleJMenuItem
Class Inheritance
Annotations
@SuppressWarnings:serial

This class implements accessibility support for the JRadioButtonMenuItem class. It provides an implementation of the Java Accessibility API appropriate to JRadioButtonMenuItem 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
AccessibleJRadioButtonMenuItem()

Constructs an AccessibleJRadioButtonMenuItem.

Method Summary

Modifier and TypeMethod and Description
public AccessibleRole

Returns:

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

Overrides javax.swing.JMenuItem.AccessibleJMenuItem.getAccessibleRole.

Get the role of this object.

Inherited from javax.swing.JMenuItem.AccessibleJMenuItem:
stateChanged

Constructor Detail

AccessibleJRadioButtonMenuItemback to summary
protected AccessibleJRadioButtonMenuItem()

Constructs an AccessibleJRadioButtonMenuItem.

Method Detail

getAccessibleRoleback to summary
public AccessibleRole getAccessibleRole()

Overrides javax.swing.JMenuItem.AccessibleJMenuItem.getAccessibleRole.

Get the role of this object.

Returns:AccessibleRole

an instance of AccessibleRole describing the role of the object