Class CheckMenuItem
java.lang.Object
javafx.scene.control.MenuItem
javafx.scene.control.CheckMenuItem
- All Implemented Interfaces:
- Styleable,- EventTarget
 A MenuItem that can be toggled between selected and unselected states.
 It is intended that CheckMenuItem be used in conjunction with the
 Menu or ContextMenu controls.
 
Creating and inserting a CheckMenuItem into a Menu is shown below.
CheckMenuItem subsystem1 = new CheckMenuItem("Enabled");
subsystem1.setOnAction(e -> System.out.println("subsystem1 #1 Enabled!"));
Menu menu = new Menu("Subsystems");
menu.getItems().add(subsystem1);
MenuBar menuBar = new MenuBar(menu); 
 Of course, the approach shown above separates out the definition of the CheckMenuItem from the Menu, but this needn't be so.
 To ascertain the current state of the CheckMenuItem, you should refer to the
 selected boolean. An example use case may be the following example:
final checkMenuItem = new CheckMenuItem("Show Widget");
subsystem1.setOnAction(e -> System.out.println("Show the widget!"));
private final BooleanProperty widgetShowing();
public final boolean isWidgetShowing() { return widgetShowing.get(); )
public final void setWidgetShowing(boolean value) {
    widgetShowingProperty().set(value);
}
public final BooleanProperty widgetShowingProperty() {
    if (widgetShowing == null) {
        widgetShowing = new SimpleBooleanProperty(this, "widgetShowing", true);
    }
    return widgetShowing;
}
widgetShowing.bind(checkMenuItem.selected);Typically a CheckMenuItem will be rendered such that, when selected, it shows a check (or tick) mark in the area normally reserved for the MenuItem graphic. Of course, this will vary depending on the skin and styling specified.
- Since:
- JavaFX 2.0
- See Also:
- 
Property SummaryPropertiesProperties 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 SummaryConstructorsConstructorDescriptionCreates an emptyCheckMenuItem.CheckMenuItem(String text) Constructs a CheckMenuItem and sets the display text with the specified text.CheckMenuItem(String text, Node graphic) Constructs a CheckMenuItem and sets the display text with the specified text and sets the graphicNodeto the given node.
- 
Method SummaryModifier and TypeMethodDescriptionfinal booleanGets the value of theselectedproperty.final BooleanPropertyRepresents the current state of this CheckMenuItem.final voidsetSelected(boolean value) Sets the value of theselectedproperty.Methods declared in class javafx.scene.control.MenuItemacceleratorProperty, 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, visiblePropertyMethods declared in class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods declared in interface javafx.event.EventTargetaddEventFilter, addEventHandler, removeEventFilter, removeEventHandlerMethods declared in interface javafx.css.StyleablegetStyleableNode
- 
Property Details- 
selectedRepresents the current state of this CheckMenuItem. Bind to this to be informed whenever the user interacts with the CheckMenuItem (and causes the selected state to be toggled).- Default value:
- false
- See Also:
 
 
- 
- 
Constructor Details- 
CheckMenuItempublic CheckMenuItem()Creates an emptyCheckMenuItem.
- 
CheckMenuItemConstructs a CheckMenuItem and sets the display text with the specified text.- Parameters:
- text- the display text
 
- 
CheckMenuItem
 
- 
- 
Method Details- 
setSelectedpublic final void setSelected(boolean value) Sets the value of theselectedproperty.- Property description:
- Represents the current state of this CheckMenuItem. Bind to this to be informed whenever the user interacts with the CheckMenuItem (and causes the selected state to be toggled).
- Default value:
- false
- Parameters:
- value- the value for the- selectedproperty
- See Also:
 
- 
isSelectedpublic final boolean isSelected()Gets the value of theselectedproperty.- Property description:
- Represents the current state of this CheckMenuItem. Bind to this to be informed whenever the user interacts with the CheckMenuItem (and causes the selected state to be toggled).
- Default value:
- false
- Returns:
- the value of the selectedproperty
- See Also:
 
- 
selectedPropertyRepresents the current state of this CheckMenuItem. Bind to this to be informed whenever the user interacts with the CheckMenuItem (and causes the selected state to be toggled).- Default value:
- false
- Returns:
- the selectedproperty
- See Also:
 
 
-