Spec-Zone.ru › OpenJavaFX 8
javafx.scene.control

Class CheckMenuItem

java.lang.Object
  • javafx.scene.control.MenuItem
    • javafx.scene.control.CheckMenuItem

All Implemented Interfaces:

Styleable, EventTarget



public class CheckMenuItem
extends MenuItem

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.

final subsystem1 = new CheckMenuItem("Enabled");
subsystem1.setOnAction(new EventHandler<ActionEvent>() {
    public void handle(ActionEvent e) {
        System.out.println("subsystem1 #1 Enabled!");
    }
});

Menu subsystemsMenu = new Menu("Subsystems");
subsystemsMenu.add(subsystem1);

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(new EventHandler<ActionEvent>() {
    public void handle(ActionEvent 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:

Menu, MenuItem, RadioMenuItem

  • Property Summary

    All MethodsInstance MethodsConcrete Methods
    Type Property and Description
    BooleanProperty selected
    Represents the current state of this CheckMenuItem.
    • Properties inherited from class javafx.scene.control.MenuItem

      accelerator, disable, graphic, id, mnemonicParsing, onAction, onMenuValidation, parentMenu, parentPopup, style, text, visible
  • Field Summary

    • Fields inherited from class javafx.scene.control.MenuItem

      MENU_VALIDATION_EVENT
  • Constructor Summary

    Constructors
    Constructor and Description
    CheckMenuItem()
    * Constructors * *
    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 graphic Node to the given node.
  • Method Summary

    All MethodsInstance MethodsConcrete Methods
    Modifier and Type Method and Description
    boolean isSelected()
    Gets the value of the property selected.
    BooleanProperty selectedProperty()
    Represents the current state of this CheckMenuItem.
    void setSelected(boolean value)
    Sets the value of the property selected.
    • Methods inherited from class javafx.scene.control.MenuItem

      acceleratorProperty, 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, toString, visibleProperty
    • Methods inherited from class java.lang.Object

      clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Property Detail

    • selected

      public final BooleanProperty selectedProperty
      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

      See Also:

      isSelected(), setSelected(boolean)

  • Constructor Detail

    • CheckMenuItem

      public CheckMenuItem()
      * Constructors * *
    • CheckMenuItem

      public CheckMenuItem(String text)
      Constructs a CheckMenuItem and sets the display text with the specified text.
    • CheckMenuItem

      public CheckMenuItem(String text,
                           Node graphic)
      Constructs a CheckMenuItem and sets the display text with the specified text and sets the graphic Node to the given node.
  • Method Detail

    • setSelected

      public final void setSelected(boolean value)
      Sets the value of the property selected.

      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

    • isSelected

      public final boolean isSelected()
      Gets the value of the property selected.

      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

    • selectedProperty

      public final BooleanProperty selectedProperty()
      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

      See Also:

      isSelected(), setSelected(boolean)

© 2008, 2025, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from JavaFX API Documentation.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Java, JavaFX and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API