Class CustomMenuItem
- All Implemented Interfaces:
Styleable, EventTarget
- Direct Known Subclasses:
SeparatorMenuItem
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:
-
Property Summary
PropertiesTypePropertyDescriptionfinal ObjectProperty<Node> The node to display within this CustomMenuItem.final BooleanPropertyIf 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, visibleTypePropertyDescriptionfinal ObjectProperty<KeyCombination> The accelerator property enables accessing the associated action in one keystroke.final BooleanPropertySets the individual disabled state of this MenuItem.final ObjectProperty<Node> An optional graphic for theMenuItem.final StringPropertyThe id of this MenuItem.final BooleanPropertyDetermines whether the mnemonic character in the menu item text will be parsed.final ObjectProperty<EventHandler<ActionEvent>> The action, which is invoked whenever the MenuItem is fired.final ObjectProperty<EventHandler<Event>> The event handler that is associated with invocation of an accelerator for a MenuItem.final ReadOnlyObjectProperty<Menu> This is theMenuin which thisMenuItemexists.This is theContextMenuin which thisMenuItemexists.final StringPropertyA string representation of the CSS style associated with this specific MenuItem.final StringPropertyThe text to display in theMenuItem.final BooleanPropertySpecifies whether this MenuItem should be rendered as part of the scene graph. -
Field Summary
Fields declared in class MenuItem
MENU_VALIDATION_EVENTModifier and TypeFieldDescriptionCalled when a accelerator for the Menuitem is invoked -
Constructor Summary
ConstructorsConstructorDescriptionCreates 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 TypeMethodDescriptionfinal ObjectProperty<Node> The node to display within this CustomMenuItem.final NodeGets the value of thecontentproperty.final BooleanPropertyIf true, this menu item, and all visible menus, will be hidden when this menu item is clicked on.final booleanGets the value of thehideOnClickproperty.final voidsetContent(Node value) Sets the value of thecontentproperty.final voidsetHideOnClick(boolean value) Sets the value of thehideOnClickproperty.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, visiblePropertyModifier and TypeMethodDescriptionfinal ObjectProperty<KeyCombination> The accelerator property enables accessing the associated action in one keystroke.Construct an event dispatch chain for this target.final BooleanPropertySets the individual disabled state of this MenuItem.voidfire()Fires a new ActionEvent.final KeyCombinationGets the value of theacceleratorproperty.List<CssMetaData<? extends Styleable, ?>> The CssMetaData of this Styleable.final NodeGets the value of thegraphicproperty.final StringgetId()Gets the value of theidproperty.final EventHandler<ActionEvent> Gets the value of theonActionproperty.final EventHandler<Event> Gets the value of theonMenuValidationproperty.final MenuGets the value of theparentMenuproperty.final ContextMenuGets the value of theparentPopupproperty.Returns an observable map of properties on this menu item for use primarily by application developers.final ObservableSet<PseudoClass> Return the pseudo-class state of this Styleable.final StringgetStyle()Gets the value of thestyleproperty.Return the parent of this Styleable, or null if there is no parent.A list of String identifiers which can be used to logically group Nodes, specifically for an external style engine.final StringgetText()Gets the value of thetextproperty.The type of thisStyleablethat is to be used in selector matching.final ObjectProperty<Node> An optional graphic for theMenuItem.final StringPropertyThe id of this MenuItem.final booleanGets the value of thedisableproperty.final booleanGets the value of themnemonicParsingproperty.final booleanGets the value of thevisibleproperty.final BooleanPropertyDetermines whether the mnemonic character in the menu item text will be parsed.final ObjectProperty<EventHandler<ActionEvent>> The action, which is invoked whenever the MenuItem is fired.final ObjectProperty<EventHandler<Event>> The event handler that is associated with invocation of an accelerator for a MenuItem.final ReadOnlyObjectProperty<Menu> This is theMenuin which thisMenuItemexists.This is theContextMenuin which thisMenuItemexists.final voidsetAccelerator(KeyCombination value) Sets the value of theacceleratorproperty.final voidsetDisable(boolean value) Sets the value of thedisableproperty.final voidsetGraphic(Node value) Sets the value of thegraphicproperty.final voidSets the value of theidproperty.final voidsetMnemonicParsing(boolean value) Sets the value of themnemonicParsingproperty.final voidsetOnAction(EventHandler<ActionEvent> value) Sets the value of theonActionproperty.final voidsetOnMenuValidation(EventHandler<Event> value) Sets the value of theonMenuValidationproperty.protected final voidsetParentMenu(Menu value) Sets the value of theparentMenuproperty.protected final voidsetParentPopup(ContextMenu value) Sets the value of theparentPopupproperty.final voidSets the value of thestyleproperty.final voidSets the value of thetextproperty.voidsetUserData(Object value) Stores a user object that contains data at their discretion.final voidsetVisible(boolean value) Sets the value of thevisibleproperty.final StringPropertyA string representation of the CSS style associated with this specific MenuItem.final StringPropertyThe text to display in theMenuItem.final BooleanPropertySpecifies whether this MenuItem should be rendered as part of the scene graph.Methods declared in class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods declared in interface EventTarget
addEventFilter, addEventHandler, removeEventFilter, removeEventHandlerModifier and TypeMethodDescriptiondefault <E extends Event>
voidaddEventFilter(EventType<E> eventType, EventHandler<? super E> eventFilter) Registers an event filter for this target.default <E extends Event>
voidaddEventHandler(EventType<E> eventType, EventHandler<? super E> eventHandler) Registers an event handler for this target.default <E extends Event>
voidremoveEventFilter(EventType<E> eventType, EventHandler<? super E> eventFilter) Unregisters a previously registered event filter from this target.default <E extends Event>
voidremoveEventHandler(EventType<E> eventType, EventHandler<? super E> eventHandler) Unregisters a previously registered event handler from this target.Methods declared in interface Styleable
getStyleableNodeModifier and TypeMethodDescriptiondefault NodeReturns the Node that represents this Styleable object.
-
Property Details
-
content
The node to display within this CustomMenuItem.- See Also:
-
hideOnClick
If true, this menu item, and all visible menus, will be hidden when this menu item is clicked on.- Default value:
- true
- See Also:
-
-
Constructor Details
-
CustomMenuItem
public CustomMenuItem()Creates a default CustomMenuItem instance. -
CustomMenuItem
Constructs a CustomMenuItem and initializes its content with the node specified.- Parameters:
node- to be embedded inside this CustomMenuItem
-
CustomMenuItem
Constructs a CustomMenuItem and sets the content to the node specified.- Parameters:
node- to be embedded inside this CustomMenuItemhideOnClick- if false the menu will not hide when the user interacts with the node.
-
-
Method Details
-
setContent
Sets the value of thecontentproperty.- Property description:
- The node to display within this CustomMenuItem.
- Parameters:
value- the value for thecontentproperty- See Also:
-
getContent
Gets the value of thecontentproperty.- Property description:
- The node to display within this CustomMenuItem.
- Returns:
- the value of the
contentproperty - See Also:
-
contentProperty
The node to display within this CustomMenuItem.- Returns:
- the
contentproperty - See Also:
-
setHideOnClick
public final void setHideOnClick(boolean value) Sets the value of thehideOnClickproperty.- 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 thehideOnClickproperty- See Also:
-
isHideOnClick
public final boolean isHideOnClick()Gets the value of thehideOnClickproperty.- 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
hideOnClickproperty - See Also:
-
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
hideOnClickproperty - See Also:
-