- All Implemented Interfaces:
- Styleable,- EventTarget,- 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.
- 
Property SummaryPropertiesTypePropertyDescriptionfinal BooleanPropertyThe selected state for thisToggle.final ObjectProperty<ToggleGroup>Represents theToggleGroupthat this RadioMenuItem belongs to.Properties declared in class javafx.scene.control.MenuItemaccelerator, disable, graphic, id, mnemonicParsing, onAction, onMenuValidation, parentMenu, parentPopup, style, text, visible
- 
Field SummaryFields declared in class javafx.scene.control.MenuItemMENU_VALIDATION_EVENT
- 
Constructor SummaryConstructorsConstructorDescriptionConstructs 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 graphicNodeto the given node.
- 
Method SummaryModifier and TypeMethodDescriptionfinal ToggleGroupGets the value of thetoggleGroupproperty.final booleanGets the value of theselectedproperty.final BooleanPropertyThe selected state for thisToggle.final voidsetSelected(boolean value) Sets the value of theselectedproperty.final voidsetToggleGroup(ToggleGroup value) Sets the value of thetoggleGroupproperty.final ObjectProperty<ToggleGroup>Represents theToggleGroupthat this RadioMenuItem belongs to.Methods declared in class javafx.scene.control.MenuItemacceleratorProperty, addEventHandler, 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, removeEventHandler, setAccelerator, setDisable, setGraphic, setId, setMnemonicParsing, setOnAction, setOnMenuValidation, setParentMenu, setParentPopup, setStyle, setText, setUserData, setVisible, styleProperty, textProperty, visiblePropertyMethods declared in class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods declared in interface javafx.css.StyleablegetStyleableNodeMethods declared in interface javafx.scene.control.TogglegetProperties, getUserData, setUserData
- 
Property Details- 
toggleGroupRepresents theToggleGroupthat this RadioMenuItem belongs to.- Specified by:
- toggleGroupPropertyin interface- Toggle
- Returns:
- the toggle group property
- See Also:
 
- 
selected- Specified by:
- selectedPropertyin interface- Toggle
- Returns:
- the selected property
- See Also:
 
 
- 
- 
Constructor Details- 
RadioMenuItempublic RadioMenuItem()Constructs a RadioMenuItem with no display text.
- 
RadioMenuItemConstructs a RadioMenuItem and sets the display text with the specified text.- Parameters:
- text- the display text
 
- 
RadioMenuItemConstructs a RadioMenuItem and sets the display text with the specified text and sets the graphicNodeto the given node.- Parameters:
- text- the display text
- graphic- the graphic node
 
 
- 
- 
Method Details- 
setToggleGroupSets the value of thetoggleGroupproperty.- Specified by:
- setToggleGroupin interface- Toggle
- Property description:
- Represents the ToggleGroupthat this RadioMenuItem belongs to.
- Parameters:
- value- the value for the- toggleGroupproperty
- See Also:
 
- 
getToggleGroupGets the value of thetoggleGroupproperty.- Specified by:
- getToggleGroupin interface- Toggle
- Property description:
- Represents the ToggleGroupthat this RadioMenuItem belongs to.
- Returns:
- the value of the toggleGroupproperty
- See Also:
 
- 
toggleGroupPropertyRepresents theToggleGroupthat this RadioMenuItem belongs to.- Specified by:
- toggleGroupPropertyin interface- Toggle
- Returns:
- the toggleGroupproperty
- See Also:
 
- 
setSelectedpublic final void setSelected(boolean value) Sets the value of theselectedproperty.- Specified by:
- setSelectedin interface- Toggle
- Property description:
- Parameters:
- value- the value for the- selectedproperty
- See Also:
 
- 
isSelectedpublic final boolean isSelected()Gets the value of theselectedproperty.- Specified by:
- isSelectedin interface- Toggle
- Property description:
- Returns:
- the value of the selectedproperty
- See Also:
 
- 
selectedPropertyDescription copied from interface:ToggleThe selected state for thisToggle.- Specified by:
- selectedPropertyin interface- Toggle
- Returns:
- the selectedproperty
- See Also:
 
 
-