CustomMenuItem (JavaFX 27)
Description: declaration: module: javafx.controls, package: javafx.scene.control, class: CustomMenuItem

# Class CustomMenuItem

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

All Implemented Interfaces:
  `Styleable, EventTarget`

Direct Known Subclasses:
  `SeparatorMenuItem`

public class CustomMenuItem extends MenuItem

A `MenuItem` that allows for arbitrary nodes to be embedded within it, by assigning a `Node` to the `content` property. CustomMenuItem attempts to make arbitrary nodes appear more natural in the Menu. For example, you automatically get hover highlighting when the user hovers their mouse over the node (or navigates to it using keyboard or other alternate means).

A useful property of this class is `hideOnClick`. This boolean specifies whether the CustomMenuItem will be automatically hidden should the user click within the bounds of the CustomMenuItem. This is of particular use when the node inside this CustomMenuItem is a control that requires user interaction, as by setting the hideOnClick property to false means the user can interact with it without the menu hiding. Note that by default hideOnClick is true.

An example of how to use CustomMenuItem is shown below.

     CustomMenuItem customMenuItem = new CustomMenuItem(new Slider());
    customMenuItem.setHideOnClick(false);

    Menu menu = new Menu("Brightness");
    menu.getItems().add(customMenuItem);
    MenuBar menuBar = new MenuBar(menu);

The slider is horizontally centered when the menu is visible, and interacting with the slider will not result in the menu disappearing.

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

- ## Property Summary

  Properties
  Type
  Property
  Description
  `final ObjectProperty<Node>`
  `content`
  The node to display within this CustomMenuItem.
  `final BooleanProperty`
  `hideOnClick`
  If true, this menu item, and all visible menus, will be hidden when this menu item is clicked on.

  ### Properties declared in class MenuItem

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

- ## Field Summary

  ### Fields declared in class MenuItem

  `MENU_VALIDATION_EVENT`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `CustomMenuItem()`
  Creates a default CustomMenuItem instance.
  `CustomMenuItem(Node node)`
  Constructs a CustomMenuItem and initializes its content with the node specified.
  `CustomMenuItem(Node node, boolean hideOnClick)`
  Constructs a CustomMenuItem and sets the content to the node specified.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `final ObjectProperty<Node>`
  `contentProperty()`
  The node to display within this CustomMenuItem.
  `final Node`
  `getContent()`
  Gets the value of the `content` property.
  `final BooleanProperty`
  `hideOnClickProperty()`
  If true, this menu item, and all visible menus, will be hidden when this menu item is clicked on.
  `final boolean`
  `isHideOnClick()`
  Gets the value of the `hideOnClick` property.
  `final void`
  `setContent(Node value)`
  Sets the value of the `content` property.
  `final void`
  `setHideOnClick(boolean value)`
  Sets the value of the `hideOnClick` property.

  ### Methods declared in class 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 Object

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

  ### Methods declared in interface EventTarget

  `addEventFilter, addEventHandler, removeEventFilter, removeEventHandler`

  ### Methods declared in interface Styleable

  `getStyleableNode`

- ## Property Details

  - ### content

    public final ObjectProperty<Node> contentProperty
    The node to display within this CustomMenuItem.
    See Also:
      - `getContent()`
      - `setContent(Node)`
      - `contentProperty()`

  - ### hideOnClick

    public final BooleanProperty hideOnClickProperty
    If true, this menu item, and all visible menus, will be hidden when this menu item is clicked on.
    Default value:
      true
    See Also:
      - `isHideOnClick()`
      - `setHideOnClick(boolean)`
      - `hideOnClickProperty()`

- ## Constructor Details

  - ### CustomMenuItem

    public CustomMenuItem()
    Creates a default CustomMenuItem instance.

  - ### CustomMenuItem

    public CustomMenuItem(Node node)
    Constructs a CustomMenuItem and initializes its content with the node specified.
    Parameters:
      `node` - to be embedded inside this CustomMenuItem

  - ### CustomMenuItem

    public CustomMenuItem(Node node, boolean hideOnClick)
    Constructs a CustomMenuItem and sets the content to the node specified.
    Parameters:
      `node` - to be embedded inside this CustomMenuItem
      `hideOnClick` - if false the menu will not hide when the user interacts with the node.

- ## Method Details

  - ### setContent

    public final void setContent(Node value)
    Sets the value of the `content` property.
    Property description:
      The node to display within this CustomMenuItem.
    Parameters:
      `value` - the value for the `content` property
    See Also:
      - `getContent()`
      - `contentProperty()`

  - ### getContent

    public final Node getContent()
    Gets the value of the `content` property.
    Property description:
      The node to display within this CustomMenuItem.
    Returns:
      the value of the `content` property
    See Also:
      - `setContent(Node)`
      - `contentProperty()`

  - ### contentProperty

    public final ObjectProperty<Node> contentProperty()
    The node to display within this CustomMenuItem.
    Returns:
      the `content` property
    See Also:
      - `getContent()`
      - `setContent(Node)`

  - ### setHideOnClick

    public final void setHideOnClick(boolean value)
    Sets the value of the `hideOnClick` property.
    Property description:
      If true, this menu item, and all visible menus, will be hidden when this menu item is clicked on.
    Default value:
      true
    Parameters:
      `value` - the value for the `hideOnClick` property
    See Also:
      - `isHideOnClick()`
      - `hideOnClickProperty()`

  - ### isHideOnClick

    public final boolean isHideOnClick()
    Gets the value of the `hideOnClick` property.
    Property description:
      If true, this menu item, and all visible menus, will be hidden when this menu item is clicked on.
    Default value:
      true
    Returns:
      the value of the `hideOnClick` property
    See Also:
      - `setHideOnClick(boolean)`
      - `hideOnClickProperty()`

  - ### hideOnClickProperty

    public final BooleanProperty hideOnClickProperty()
    If true, this menu item, and all visible menus, will be hidden when this menu item is clicked on.
    Default value:
      true
    Returns:
      the `hideOnClick` property
    See Also:
      - `isHideOnClick()`
      - `setHideOnClick(boolean)`