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..
ButtonGroup
| Modifier and Type | Class and Description |
|---|---|
| protected class | JRadioButtonMenuItem.
This class implements accessibility support for the
|
| Modifier and Type | Field and Description |
|---|---|
| private static final String |
| Access | Constructor and Description |
|---|---|
| public | |
| public | JRadioButtonMenuItem(Icon
the icon)Icon to display on the
JRadioButtonMenuItemCreates a |
| public | JRadioButtonMenuItem(String
the text of the text)JRadioButtonMenuItemCreates a |
| public | JRadioButtonMenuItem(Action
the a)Action on which to base the radio
button menu itemCreates a radio button menu item whose properties are taken from the
|
| public | JRadioButtonMenuItem(String
the text of the text, Icon JRadioButtonMenuItemthe icon to display on the icon)JRadioButtonMenuItemCreates a radio button menu item with the specified text
and |
| public | JRadioButtonMenuItem(String
the text of the text, boolean CheckBoxMenuItemthe selected state of the selected)CheckBoxMenuItemCreates 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 selected)true, the button is initially selected,
otherwise, the button is initially unselectedCreates a radio button menu item that has the specified text, image, and selection state. |
| Modifier and Type | Method and Description |
|---|---|
| public AccessibleContext | Returns: an AccessibleJRadioButtonMenuItem that serves as the AccessibleContext of this JRadioButtonMenuItemOverrides javax. Implements javax. Gets the AccessibleContext associated with this JRadioButtonMenuItem. |
| public String | Returns: the string "RadioButtonMenuItemUI"Overrides javax. Returns the name of the L&F class that renders this component. |
| protected String | Returns: a string representation of thisJRadioButtonMenuItemOverrides javax. Returns a string representation of this
|
| pack-priv boolean | shouldUpdateSelectedStateFromAction()
Overrides javax. Overridden to return true, JRadioButtonMenuItem supports the selected state. |
| private void | writeObject(ObjectOutputStream s)
Hides javax. See |
| uiClassID | back to summary |
|---|---|
| private static final String uiClassID Hides javax.
| |
| JRadioButtonMenuItem | back to summary |
|---|---|
| public JRadioButtonMenuItem() Creates a | |
| JRadioButtonMenuItem | back to summary |
|---|---|
| public JRadioButtonMenuItem(Icon icon) Creates a
| |
| JRadioButtonMenuItem | back to summary |
|---|---|
| public JRadioButtonMenuItem(String text) Creates a
| |
| JRadioButtonMenuItem | back to summary |
|---|---|
| public JRadioButtonMenuItem(Action a) Creates a radio button menu item whose properties are taken from the
| |
| JRadioButtonMenuItem | back to summary |
|---|---|
| public JRadioButtonMenuItem(String text, Icon icon) Creates a radio button menu item with the specified text
and | |
| JRadioButtonMenuItem | back to summary |
|---|---|
| public JRadioButtonMenuItem(String text, boolean selected) Creates a radio button menu item with the specified text and selection state.
| |
| JRadioButtonMenuItem | back to summary |
|---|---|
| public JRadioButtonMenuItem(Icon icon, boolean selected) Creates a radio button menu item with the specified image and selection state, but no text.
| |
| JRadioButtonMenuItem | back 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. | |
| getAccessibleContext | back to summary |
|---|---|
| public AccessibleContext getAccessibleContext() Overrides javax. Implements javax. 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.
| |
| getUIClassID | back to summary |
|---|---|
| public String getUIClassID() Overrides javax. Returns the name of the L&F class that renders this component.
| |
| paramString | back to summary |
|---|---|
| protected String paramString() Overrides javax. Returns a string representation of this
| |
| shouldUpdateSelectedStateFromAction | back to summary |
|---|---|
| pack-priv boolean shouldUpdateSelectedStateFromAction() Overrides javax. Overridden to return true, JRadioButtonMenuItem supports the selected state. | |
| writeObject | back to summary |
|---|---|
| private void writeObject(ObjectOutputStream s) throws IOException Hides javax. See
| |
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..
| Access | Constructor and Description |
|---|---|
| protected |
| Modifier and Type | Method and Description |
|---|---|
| public AccessibleRole | Returns: an instance of AccessibleRole describing the role of the objectOverrides javax. Get the role of this object. |
| AccessibleJRadioButtonMenuItem | back to summary |
|---|---|
| protected AccessibleJRadioButtonMenuItem() Constructs an | |
| getAccessibleRole | back to summary |
|---|---|
| public AccessibleRole getAccessibleRole() Overrides javax. Get the role of this object.
| |