# Class RadioMenuItem

java.lang.Object
javafx.scene.control.MenuItem
javafx.scene.control.RadioMenuItem

All Implemented Interfaces:
  `Styleable`, `EventTarget`, `Toggle`

public class RadioMenuItem extends MenuItem implements Toggle

A RadioMenuItem is a `MenuItem` that can be toggled (it uses the `Toggle` mixin). This means that RadioMenuItem has an API very similar in nature to other controls that use `Toggle`, such as `RadioButton` and `ToggleButton`. RadioMenuItem is specifically designed for use within a `Menu`, so refer to that class API documentation for more information on how to add a RadioMenuItem into it.

To create a simple, ungrouped RadioMenuItem, do the following:

    RadioMenuItem radioItem = new RadioMenuItem("radio text");
    radioItem.setSelected(false);
    radioItem.setOnAction(e -> System.out.println("radio toggled"));

The problem with the example above is that this offers no benefit over using a normal MenuItem. As already mentioned, the purpose of a RadioMenuItem is to offer multiple choices to the user, and only allow for one of these choices to be selected at any one time (i.e. the selection should be mutually exclusive). To achieve this, you can place zero or more RadioMenuItem's into groups. When in groups, only one RadioMenuItem at a time within that group can be selected. To put two RadioMenuItem instances into the same group, simply assign them both the same value for `toggleGroup`. For example:

    ToggleGroup toggleGroup = new ToggleGroup();

    RadioMenuItem radioItem1 = new RadioMenuItem("Option 1");
    radioItem1.setOnAction(e -> System.out.println("radio1 toggled"));
    radioItem1.setToggleGroup(toggleGroup);

    RadioMenuItem radioItem2 = new RadioMenuItem("Option 2");
    radioItem2.setOnAction(e -> System.out.println("radio2 toggled"));
    radioItem2.setToggleGroup(toggleGroup);

    Menu menu = new Menu("Selection");
    menu.getItems().addAll(radioItem1, radioItem2);
    MenuBar menuBar = new MenuBar(menu);

In this example, with both RadioMenuItem's assigned to the same `ToggleGroup`, only one item may be selected at any one time, and should the selection change, the ToggleGroup will take care of deselecting the previous item.

Since:
  JavaFX 2.0
See Also:
  - `MenuItem`
  - `Menu`

- ## Property Summary

  Properties
  Type
  Property
  Description
  `final BooleanProperty`
  `selected`
  The selected state for this `Toggle`.
  `final ObjectProperty<ToggleGroup>`
  `toggleGroup`
  Represents the `ToggleGroup` that this RadioMenuItem belongs to.

  ### Properties declared in class javafx.scene.control.MenuItem

  `accelerator, disable, graphic, id, mnemonicParsing, onAction, onMenuValidation, parentMenu, parentPopup, style, text, visible`

- ## Field Summary

  ### Fields declared in class javafx.scene.control.MenuItem

  `MENU_VALIDATION_EVENT`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `RadioMenuItem()`
  Constructs a RadioMenuItem with no display text.
  `RadioMenuItem(String text)`
  Constructs a RadioMenuItem and sets the display text with the specified text.
  `RadioMenuItem(String text, Node graphic)`
  Constructs a RadioMenuItem and sets the display text with the specified text and sets the graphic `Node` to the given node.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `final ToggleGroup`
  `getToggleGroup()`
  Gets the value of the `toggleGroup` property.
  `final boolean`
  `isSelected()`
  Gets the value of the `selected` property.
  `final BooleanProperty`
  `selectedProperty()`
  The selected state for this `Toggle`.
  `final void`
  `setSelected(boolean value)`
  Sets the value of the `selected` property.
  `final void`
  `setToggleGroup(ToggleGroup value)`
  Sets the value of the `toggleGroup` property.
  `final ObjectProperty<ToggleGroup>`
  `toggleGroupProperty()`
  Represents the `ToggleGroup` that this RadioMenuItem belongs to.

  ### Methods declared in class javafx.scene.control.MenuItem

  `acceleratorProperty, buildEventDispatchChain, disableProperty, fire, getAccelerator, getCssMetaData, getGraphic, getId, getOnAction, getOnMenuValidation, getParentMenu, getParentPopup, getProperties, getPseudoClassStates, getStyle, getStyleableParent, getStyleClass, getText, getTypeSelector, getUserData, graphicProperty, idProperty, isDisable, isMnemonicParsing, isVisible, mnemonicParsingProperty, onActionProperty, onMenuValidationProperty, parentMenuProperty, parentPopupProperty, setAccelerator, setDisable, setGraphic, setId, setMnemonicParsing, setOnAction, setOnMenuValidation, setParentMenu, setParentPopup, setStyle, setText, setUserData, setVisible, styleProperty, textProperty, visibleProperty`

  ### Methods declared in class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

  ### Methods declared in interface javafx.event.EventTarget

  `addEventFilter, addEventHandler, removeEventFilter, removeEventHandler`

  ### Methods declared in interface javafx.css.Styleable

  `getStyleableNode`

  ### Methods declared in interface javafx.scene.control.Toggle

  `getProperties, getUserData, setUserData`

- ## Property Details

  - ### toggleGroup

    public final ObjectProperty<ToggleGroup> toggleGroupProperty
    Represents the `ToggleGroup` that this RadioMenuItem belongs to.
    Specified by:
      `toggleGroupProperty` in interface `Toggle`
    Returns:
      the toggle group property
    See Also:
      - `getToggleGroup()`
      - `setToggleGroup(ToggleGroup)`
      - `toggleGroupProperty()`

  - ### selected

    public final BooleanProperty selectedProperty
    Specified by:
      `selectedProperty` in interface `Toggle`
    Returns:
      the selected property
    See Also:
      - `isSelected()`
      - `setSelected(boolean)`
      - `selectedProperty()`

- ## Constructor Details

  - ### RadioMenuItem

    public RadioMenuItem()
    Constructs a RadioMenuItem with no display text.

  - ### RadioMenuItem

    public RadioMenuItem(String text)
    Constructs a RadioMenuItem and sets the display text with the specified text.
    Parameters:
      `text` - the display text

  - ### RadioMenuItem

    public RadioMenuItem(String text, Node graphic)
    Constructs a RadioMenuItem and sets the display text with the specified text and sets the graphic `Node` to the given node.
    Parameters:
      `text` - the display text
      `graphic` - the graphic node

- ## Method Details

  - ### setToggleGroup

    public final void setToggleGroup(ToggleGroup value)
    Sets the value of the `toggleGroup` property.
    Specified by:
      `setToggleGroup` in interface `Toggle`
    Property description:
      Represents the `ToggleGroup` that this RadioMenuItem belongs to.
    Parameters:
      `value` - the value for the `toggleGroup` property
    See Also:
      - `getToggleGroup()`
      - `toggleGroupProperty()`

  - ### getToggleGroup

    public final ToggleGroup getToggleGroup()
    Gets the value of the `toggleGroup` property.
    Specified by:
      `getToggleGroup` in interface `Toggle`
    Property description:
      Represents the `ToggleGroup` that this RadioMenuItem belongs to.
    Returns:
      the value of the `toggleGroup` property
    See Also:
      - `setToggleGroup(ToggleGroup)`
      - `toggleGroupProperty()`

  - ### toggleGroupProperty

    public final ObjectProperty<ToggleGroup> toggleGroupProperty()
    Represents the `ToggleGroup` that this RadioMenuItem belongs to.
    Specified by:
      `toggleGroupProperty` in interface `Toggle`
    Returns:
      the `toggleGroup` property
    See Also:
      - `getToggleGroup()`
      - `setToggleGroup(ToggleGroup)`

  - ### setSelected

    public final void setSelected(boolean value)
    Sets the value of the `selected` property.
    Specified by:
      `setSelected` in interface `Toggle`
    Property description:
    Parameters:
      `value` - the value for the `selected` property
    See Also:
      - `isSelected()`
      - `selectedProperty()`

  - ### isSelected

    public final boolean isSelected()
    Gets the value of the `selected` property.
    Specified by:
      `isSelected` in interface `Toggle`
    Property description:
    Returns:
      the value of the `selected` property
    See Also:
      - `setSelected(boolean)`
      - `selectedProperty()`

  - ### selectedProperty

    public final BooleanProperty selectedProperty()
    Description copied from interface: `Toggle`
    The selected state for this `Toggle`.
    Specified by:
      `selectedProperty` in interface `Toggle`
    Returns:
      the `selected` property
    See Also:
      - `isSelected()`
      - `setSelected(boolean)`