APIdia Launch Partner
Top Description Fields Constructors Methods
javafx.scene.control

public Class CustomMenuItem

extends MenuItem
Class Inheritance
Known Direct Subclasses
javafx.scene.control.SeparatorMenuItem, com.sun.javafx.scene.control.GlobalMenuAdapter.CustomMenuItemAdapter
Imports
javafx.beans.property.BooleanProperty, .ObjectProperty, .SimpleBooleanProperty, .SimpleObjectProperty, javafx.scene.Node

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);
Image of the CustomMenuItem control

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

Field Summary

Modifier and TypeField and Description
private ObjectProperty<Node>
content

The node to display within this CustomMenuItem.

private static final String
private BooleanProperty
hideOnClick

If true, this menu item, and all visible menus, will be hidden when this menu item is clicked on.

Inherited from javafx.scene.control.MenuItem:
eventHandlerManagerMENU_VALIDATION_EVENT

Constructor Summary

AccessConstructor and Description
public
CustomMenuItem()

Creates a default CustomMenuItem instance.

public
CustomMenuItem(Node
to be embedded inside this CustomMenuItem
node
)

Constructs a CustomMenuItem and initializes its content with the node specified.

public
CustomMenuItem(Node
to be embedded inside this CustomMenuItem
node
,
boolean
if false the menu will not hide when the user interacts with the node.
hideOnClick
)

Constructs a CustomMenuItem and sets the content to the node specified.

Method Summary

Modifier and TypeMethod and Description
public final ObjectProperty<Node>
public final Node
public final BooleanProperty
public final boolean
public final void
public final void
setHideOnClick(boolean value)

Inherited from javafx.scene.control.MenuItem:
acceleratorPropertyaddEventFilteraddEventHandlerbuildEventDispatchChaindisablePropertyfiregetAcceleratorgetCssMetaDatagetGraphicgetIdgetOnActiongetOnMenuValidationgetParentMenugetParentPopupgetPropertiesgetPseudoClassStatesgetStylegetStyleableNodegetStyleableParentgetStyleClassgetTextgetTypeSelectorgetUserDatagraphicPropertyidPropertyisDisableisMnemonicParsingisVisiblemnemonicParsingPropertyonActionPropertyonMenuValidationPropertyparentMenuPropertyparentPopupPropertyremoveEventFilterremoveEventHandlersetAcceleratorsetDisablesetGraphicsetIdsetMnemonicParsingsetOnActionsetOnMenuValidationsetParentMenusetParentPopupsetStylesetTextsetUserDatasetVisiblestylePropertytextPropertytoStringvisibleProperty

Field Detail

contentback to summary
private ObjectProperty<Node> content

The node to display within this CustomMenuItem.

DEFAULT_STYLE_CLASSback to summary
private static final String DEFAULT_STYLE_CLASS

Hides javafx.scene.control.MenuItem.DEFAULT_STYLE_CLASS.

hideOnClickback to summary
private BooleanProperty hideOnClick

If true, this menu item, and all visible menus, will be hidden when this menu item is clicked on.

Default Value
true

Constructor Detail

CustomMenuItemback to summary
public CustomMenuItem()

Creates a default CustomMenuItem instance.

CustomMenuItemback to summary
public CustomMenuItem(Node node)

Constructs a CustomMenuItem and initializes its content with the node specified.

Parameters
node:Node

to be embedded inside this CustomMenuItem

CustomMenuItemback to summary
public CustomMenuItem(Node node, boolean hideOnClick)

Constructs a CustomMenuItem and sets the content to the node specified.

Parameters
node:Node

to be embedded inside this CustomMenuItem

hideOnClick:boolean

if false the menu will not hide when the user interacts with the node.

Method Detail

contentPropertyback to summary
public final ObjectProperty<Node> contentProperty()
getContentback to summary
public final Node getContent()
hideOnClickPropertyback to summary
public final BooleanProperty hideOnClickProperty()
isHideOnClickback to summary
public final boolean isHideOnClick()
setContentback to summary
public final void setContent(Node value)
setHideOnClickback to summary
public final void setHideOnClick(boolean value)