- All Implemented Interfaces:
- Styleable,- EventTarget
A popup menu of actionable items which is displayed to the user only upon request. When a menu is visible, in most use cases, the user can select one menu item before the menu goes back to its hidden state. This means the menu is a good place to put important functionality that does not necessarily need to be visible at all times to the user.
 Menus are typically placed in a MenuBar, or as a submenu of another Menu.
 If the intention is to offer a context menu when the user right-clicks in a
 certain area of their user interface, then this is the wrong control to use.
 This is because when Menu is added to the scenegraph, it has a visual
 representation that will result in it appearing on screen. Instead,
 ContextMenu should be used in this circumstance.
 
Creating a Menu and inserting it into a MenuBar is easy, as shown below:
 Menu menu1 = new Menu("File");
 MenuBar menuBar = new MenuBar(menu1);
 A Menu is a subclass of MenuItem which means that it can be inserted
 into a Menu's items ObservableList, resulting in a submenu being created:
 
 MenuItem menu12 = new MenuItem("Open");
 menu1.getItems().add(menu12); 
 
 The items ObservableList allows for any MenuItem type to be inserted,
 including its subclasses Menu, MenuItem, RadioMenuItem, CheckMenuItem,
 CustomMenuItem and SeparatorMenuItem. In order to insert an arbitrary Node to
 a Menu, a CustomMenuItem can be used. One exception to this general rule is that
 SeparatorMenuItem could be used for inserting a separator.
- 
Property SummaryPropertiesTypePropertyDescriptionfinal ObjectProperty<EventHandler<Event>>Called just after theContextMenuhas been hidden.final ObjectProperty<EventHandler<Event>>Called just prior to theContextMenubeing hidden.final ObjectProperty<EventHandler<Event>>Called just prior to theContextMenubeing shown, even if the menu has no items to show.final ObjectProperty<EventHandler<Event>>Called just after theContextMenuis shown.final ReadOnlyBooleanPropertyIndicates whether theContextMenuis currently visible.Properties declared in class javafx.scene.control.MenuItemaccelerator, disable, graphic, id, mnemonicParsing, onAction, onMenuValidation, parentMenu, parentPopup, style, text, visible
- 
Field SummaryFieldsModifier and TypeFieldDescriptionCalled when the contextMenu for this menu is hidden.Called when the contextMenu for this menu will be hidden.Called when the contextMenu for this menu will be shown.Called when the contextMenu for this menu shows.Fields declared in class javafx.scene.control.MenuItemMENU_VALIDATION_EVENT
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionfinal ObservableList<MenuItem>getItems()The items to show within this menu.final EventHandler<Event>Gets the value of the property onHidden.final EventHandler<Event>Gets the value of the property onHiding.final EventHandler<Event>Gets the value of the property onShowing.final EventHandler<Event>Gets the value of the property onShown.voidhide()Hides theContextMenuif it was previously showing, and any showing submenus.final booleanGets the value of the property showing.final ObjectProperty<EventHandler<Event>>Called just after theContextMenuhas been hidden.final ObjectProperty<EventHandler<Event>>Called just prior to theContextMenubeing hidden.final ObjectProperty<EventHandler<Event>>Called just prior to theContextMenubeing shown, even if the menu has no items to show.final ObjectProperty<EventHandler<Event>>Called just after theContextMenuis shown.final voidsetOnHidden(EventHandler<Event> value) Sets the value of the property onHidden.final voidsetOnHiding(EventHandler<Event> value) Sets the value of the property onHiding.final voidsetOnShowing(EventHandler<Event> value) Sets the value of the property onShowing.final voidsetOnShown(EventHandler<Event> value) Sets the value of the property onShown.voidshow()If the Menu is not disabled and theContextMenuis not already showing, then this will cause theContextMenuto be shown.final ReadOnlyBooleanPropertyIndicates whether theContextMenuis currently visible.Methods declared in class javafx.scene.control.MenuItemacceleratorProperty, 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, visiblePropertyMethods declared in class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods declared in interface javafx.css.StyleablegetStyleableNode
- 
Property Details- 
showingIndicates whether theContextMenuis currently visible.- Default value:
- false
- See Also:
 
- 
onShowingCalled just prior to theContextMenubeing shown, even if the menu has no items to show. Note however that this won't be called if the menu does not have a valid anchor node.- See Also:
 
- 
onShownCalled just after theContextMenuis shown.- See Also:
 
- 
onHidingCalled just prior to theContextMenubeing hidden.- See Also:
 
- 
onHiddenCalled just after theContextMenuhas been hidden.- See Also:
 
 
- 
- 
Field Details- 
ON_SHOWINGCalled when the contextMenu for this menu will be shown. However if the contextMenu is empty then this will not be called. 
- 
ON_SHOWNCalled when the contextMenu for this menu shows. However if the contextMenu is empty then this will not be called. 
- 
ON_HIDINGCalled when the contextMenu for this menu will be hidden. However if the contextMenu is empty then this will not be called. 
- 
ON_HIDDENCalled when the contextMenu for this menu is hidden. However if the contextMenu is empty then this will not be called. 
 
- 
- 
Constructor Details- 
Menupublic Menu()Constructs a Menu with an empty string for its display text.- Since:
- JavaFX 2.2
 
- 
MenuConstructs a Menu and sets the display text with the specified text.- Parameters:
- text- the text to display on the menu button
 
- 
MenuConstructs a Menu and sets the display text with the specified text and sets the graphicNodeto the given node.- Parameters:
- text- the text to display on the menu button
- graphic- the graphic to display on the menu button
 
- 
MenuConstructs a Menu and sets the display text with the specified text, the graphicNodeto the given node, and inserts the given items into theitemslist.- Parameters:
- text- the text to display on the menu button
- graphic- the graphic to display on the menu button
- items- The items to display in the popup menu.
- Since:
- JavaFX 8u40
 
 
- 
- 
Method Details- 
isShowingpublic final boolean isShowing()Gets the value of the property showing.- Property description:
- Indicates whether the ContextMenuis currently visible.
- Default value:
- false
 
- 
showingPropertyIndicates whether theContextMenuis currently visible.- Default value:
- false
- See Also:
 
- 
onShowingPropertyCalled just prior to theContextMenubeing shown, even if the menu has no items to show. Note however that this won't be called if the menu does not have a valid anchor node.- See Also:
 
- 
setOnShowingSets the value of the property onShowing.- Property description:
- Called just prior to the ContextMenubeing shown, even if the menu has no items to show. Note however that this won't be called if the menu does not have a valid anchor node.
 
- 
getOnShowingGets the value of the property onShowing.- Property description:
- Called just prior to the ContextMenubeing shown, even if the menu has no items to show. Note however that this won't be called if the menu does not have a valid anchor node.
 
- 
onShownPropertyCalled just after theContextMenuis shown.- See Also:
 
- 
setOnShownSets the value of the property onShown.- Property description:
- Called just after the ContextMenuis shown.
 
- 
getOnShownGets the value of the property onShown.- Property description:
- Called just after the ContextMenuis shown.
 
- 
onHidingPropertyCalled just prior to theContextMenubeing hidden.- See Also:
 
- 
setOnHidingSets the value of the property onHiding.- Property description:
- Called just prior to the ContextMenubeing hidden.
 
- 
getOnHidingGets the value of the property onHiding.- Property description:
- Called just prior to the ContextMenubeing hidden.
 
- 
onHiddenPropertyCalled just after theContextMenuhas been hidden.- See Also:
 
- 
setOnHiddenSets the value of the property onHidden.- Property description:
- Called just after the ContextMenuhas been hidden.
 
- 
getOnHiddenGets the value of the property onHidden.- Property description:
- Called just after the ContextMenuhas been hidden.
 
- 
getItemsThe items to show within this menu. If this ObservableList is modified at runtime, the Menu will update as expected.- Returns:
- the list of items
 
- 
showpublic void show()If the Menu is not disabled and theContextMenuis not already showing, then this will cause theContextMenuto be shown.
- 
hidepublic void hide()Hides theContextMenuif it was previously showing, and any showing submenus. If this menu is not showing, then invoking this function has no effect.
 
-