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);
If this CustomMenuItem, with the Slider
within it, is placed in a
menu, you'll be presented with a slider that is horizontally centered when
the menu is visible, and interacting with the slider will not result in the
menu disappearing.
Type | Property and Description |
---|---|
ObjectProperty<Node> |
content
The node to display within this CustomMenuItem.
|
BooleanProperty |
hideOnClick
If true, this menu item, and all visible menus, will be hidden when this
menu item is clicked on.
|
accelerator, disable, graphic, id, mnemonicParsing, onAction, onMenuValidation, parentMenu, parentPopup, style, text, visible
MENU_VALIDATION_EVENT
Constructor and Description |
---|
CustomMenuItem() |
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.
|
Modifier and Type | Method and Description |
---|---|
ObjectProperty<Node> |
contentProperty()
The node to display within this CustomMenuItem.
|
Node |
getContent()
Gets the value of the property content.
|
BooleanProperty |
hideOnClickProperty()
If true, this menu item, and all visible menus, will be hidden when this
menu item is clicked on.
|
boolean |
isHideOnClick()
Gets the value of the property hideOnClick.
|
void |
setContent(Node value)
Sets the value of the property content.
|
void |
setHideOnClick(boolean value)
Sets the value of the property hideOnClick.
|
acceleratorProperty, addEventHandler, buildEventDispatchChain, disableProperty, fire, getAccelerator, getGraphic, getId, getOnAction, getOnMenuValidation, getParentMenu, getParentPopup, getProperties, getStyle, getStyleClass, getText, 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, visibleProperty
public final ObjectProperty<Node> contentProperty
getContent()
,
setContent(Node)
public final BooleanProperty hideOnClickProperty
isHideOnClick()
,
setHideOnClick(boolean)
public CustomMenuItem()
public CustomMenuItem(Node node)
node
- to be embedded inside this CustomMenuItempublic CustomMenuItem(Node node, boolean hideOnClick)
node
- to be embedded inside this CustomMenuItemhideOnClick
- if false the menu will not hide when the user interacts with the node.public final void setContent(Node value)
public final Node getContent()
public final ObjectProperty<Node> contentProperty()
getContent()
,
setContent(Node)
public final void setHideOnClick(boolean value)
public final boolean isHideOnClick()
public final BooleanProperty hideOnClickProperty()
isHideOnClick()
,
setHideOnClick(boolean)
Copyright (c) 2008, 2014, Oracle and/or its affiliates. All rights reserved.