- All Implemented Interfaces:
MFXStyleablePopup,Styleable,EventTarget,Skinnable
MFXContextMenu is a special case of MFXPopup.
The content is determined by its skin, and also has a userAgentStylesheet to define
the default style for all MFXContextMenus.
You can easily manage on what condition to show the popup and where to show it by changing these
two properties:
- showConditionProperty(): by default checks if the pressed mouse button was the SECONDARY button
- showActionProperty(): by default calls MFXPopup.show(Node, double, double) with the mouse screen coordinates
The new implementation allows adding generic separators, not only lines, addSeparator(Node),
usually this is a Label to categorize the menu items.
The new implementation also allows to disable the popup. The disabled state is used by the default
showConditionProperty(), so keep in mind that if you change that the disabled state
will be ignored (unless specified by your logic of course).
MFXContextMenu.Builder class to create a context menu.
NOTE that since the content of the context menu is entirely determined by its skin, the MFXPopup.contentProperty()
will always be null. As a result methods involving Alignment, HPos or VPos will fail with a
NullPointerException.-
Property Summary
PropertiesTypePropertyDescriptionSpecifies the action to perform when a valid MouseEvent occurs.Specifies the function used to determine if a MouseEvent should trigger theshowActionProperty().Properties inherited from class javafx.scene.control.PopupControl
id, maxHeight, maxWidth, minHeight, minWidth, prefHeight, prefWidth, skin, styleProperties inherited from class javafx.stage.PopupWindow
anchorLocation, anchorX, anchorY, autoFix, autoHide, consumeAutoHidingEvents, hideOnEscape, onAutoHide, ownerNode, ownerWindowProperties inherited from class javafx.stage.Window
eventDispatcher, focused, forceIntegerRenderScale, height, onCloseRequest, onHidden, onHiding, onShowing, onShown, opacity, outputScaleX, outputScaleY, renderScaleX, renderScaleY, scene, showing, width, x, y -
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder class that facilitates the creation of context menus with fluent api.Nested classes/interfaces inherited from class io.github.palexdev.materialfx.controls.MFXPopup
MFXPopup.MFXPopupEventNested classes/interfaces inherited from class javafx.scene.control.PopupControl
PopupControl.CSSBridgeNested classes/interfaces inherited from class javafx.stage.PopupWindow
PopupWindow.AnchorLocation -
Field Summary
Fields inherited from class javafx.scene.control.PopupControl
USE_COMPUTED_SIZE, USE_PREF_SIZE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddItem(MFXContextMenuItem item) Adds the giver menu item to the items list.voidaddItems(MFXContextMenuItem... items) Adds the given menu items to the items list.voidaddLineSeparator(Line separator) Adds the given line which acts as a separator to the items list.voidaddSeparator(Node separator) Adds the given node which acts as a separator to the items list.protected Skin<?>voiddispose()Callsuninstall()but also sets all the handlers and the owner node to null, making this context menu not usable anymore.getItems()getOwner()Gets the value of the property showAction.Gets the value of the property showCondition.This method works just likeRegion.getUserAgentStylesheet().voidinstall()Adds the needed handlers on the owner node.booleanvoidsetDisabled(boolean disabled) Enables/Disables the context menu.voidsetShowAction(Consumer<MouseEvent> showAction) Sets the value of the property showAction.voidsetShowCondition(Function<MouseEvent, Boolean> showCondition) Sets the value of the property showCondition.Specifies the action to perform when a valid MouseEvent occurs.Specifies the function used to determine if a MouseEvent should trigger theshowActionProperty().voidRemoves any added handler from the owner node.Methods inherited from class io.github.palexdev.materialfx.controls.MFXPopup
computePosition, contentProperty, fixPosition, getAnimationProvider, getContent, getPopupStyleableParent, getPosition, getStyleableParent, getStyleSheets, hide, hoverProperty, isAnimated, isFixPosition, isHover, reposition, setAnimated, setAnimationProvider, setContent, setHover, setPopupStyleableParent, show, show, show, showMethods inherited from class javafx.scene.control.PopupControl
getClassCssMetaData, getCssMetaData, getId, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getPrefHeight, getPrefWidth, getPseudoClassStates, getSkin, getStyle, getStyleableNode, getStyleClass, getTypeSelector, idProperty, maxHeight, maxHeightProperty, maxWidth, maxWidthProperty, minHeight, minHeightProperty, minWidth, minWidthProperty, prefHeight, prefHeightProperty, prefWidth, prefWidthProperty, pseudoClassStateChanged, setId, setMaxHeight, setMaxSize, setMaxWidth, setMinHeight, setMinSize, setMinWidth, setPrefHeight, setPrefSize, setPrefWidth, setSkin, setStyle, skinProperty, stylePropertyMethods inherited from class javafx.stage.PopupWindow
anchorLocationProperty, anchorXProperty, anchorYProperty, autoFixProperty, autoHideProperty, consumeAutoHidingEventsProperty, getAnchorLocation, getAnchorX, getAnchorY, getConsumeAutoHidingEvents, getOnAutoHide, getOwnerNode, getOwnerWindow, hideOnEscapeProperty, isAutoFix, isAutoHide, isHideOnEscape, onAutoHideProperty, ownerNodeProperty, ownerWindowProperty, setAnchorLocation, setAnchorX, setAnchorY, setAutoFix, setAutoHide, setConsumeAutoHidingEvents, setHideOnEscape, setOnAutoHide, setScene, show, showMethods inherited from class javafx.stage.Window
addEventFilter, addEventHandler, buildEventDispatchChain, centerOnScreen, eventDispatcherProperty, fireEvent, focusedProperty, forceIntegerRenderScaleProperty, getEventDispatcher, getHeight, getOnCloseRequest, getOnHidden, getOnHiding, getOnShowing, getOnShown, getOpacity, getOutputScaleX, getOutputScaleY, getProperties, getRenderScaleX, getRenderScaleY, getScene, getUserData, getWidth, getWindows, getX, getY, hasProperties, heightProperty, isFocused, isForceIntegerRenderScale, isShowing, onCloseRequestProperty, onHiddenProperty, onHidingProperty, onShowingProperty, onShownProperty, opacityProperty, outputScaleXProperty, outputScaleYProperty, removeEventFilter, removeEventHandler, renderScaleXProperty, renderScaleYProperty, requestFocus, sceneProperty, setEventDispatcher, setEventHandler, setForceIntegerRenderScale, setHeight, setOnCloseRequest, setOnHidden, setOnHiding, setOnShowing, setOnShown, setOpacity, setRenderScaleX, setRenderScaleY, setUserData, setWidth, setX, setY, show, showingProperty, sizeToScene, widthProperty, xProperty, yProperty
-
Property Details
-
showCondition
Specifies the function used to determine if a MouseEvent should trigger theshowActionProperty().By default, checks if the SECONDARY mouse button was pressed.
- See Also:
-
showAction
Specifies the action to perform when a valid MouseEvent occurs.By default, calls
MFXPopup.show(Node, double, double)with the MouseEvent screen coordinates.- See Also:
-
-
Constructor Details
-
MFXContextMenu
-
-
Method Details
-
install
public void install()Adds the needed handlers on the owner node. -
uninstall
public void uninstall()Removes any added handler from the owner node. -
dispose
public void dispose()Callsuninstall()but also sets all the handlers and the owner node to null, making this context menu not usable anymore. -
addItem
Adds the giver menu item to the items list. -
addItems
Adds the given menu items to the items list. -
addSeparator
Adds the given node which acts as a separator to the items list. -
addLineSeparator
Adds the given line which acts as a separator to the items list. It's suggested to useMFXContextMenu.Builder.getLineSeparator()orMFXContextMenu.Builder.getLineSeparator(Insets)to generate the Line. -
createDefaultSkin
- Overrides:
createDefaultSkinin classMFXPopup
-
getUserAgentStylesheet
Description copied from interface:MFXStyleablePopupThis method works just likeRegion.getUserAgentStylesheet(). AnyMFXStyleablePopupshould offer the possibility of setting a base stylesheet. It's up to the skin on how to use it though (an example can be found hereMFXContextMenuSkin).- Specified by:
getUserAgentStylesheetin interfaceMFXStyleablePopup- Overrides:
getUserAgentStylesheetin classMFXPopup
-
isDisabled
public boolean isDisabled()- Returns:
- whether the context menu is disabled
-
setDisabled
public void setDisabled(boolean disabled) Enables/Disables the context menu. -
getItems
- Returns:
- the list containing the context menu's items
-
getOwner
- Returns:
- this context menu's owner
-
getShowCondition
Gets the value of the property showCondition.- Property description:
- Specifies the function used to determine if a MouseEvent should trigger
the
showActionProperty().By default, checks if the SECONDARY mouse button was pressed.
-
showConditionProperty
Specifies the function used to determine if a MouseEvent should trigger theshowActionProperty().By default, checks if the SECONDARY mouse button was pressed.
- See Also:
-
setShowCondition
Sets the value of the property showCondition.- Property description:
- Specifies the function used to determine if a MouseEvent should trigger
the
showActionProperty().By default, checks if the SECONDARY mouse button was pressed.
-
getShowAction
Gets the value of the property showAction.- Property description:
- Specifies the action to perform when a valid MouseEvent occurs.
By default, calls
MFXPopup.show(Node, double, double)with the MouseEvent screen coordinates.
-
showActionProperty
Specifies the action to perform when a valid MouseEvent occurs.By default, calls
MFXPopup.show(Node, double, double)with the MouseEvent screen coordinates.- See Also:
-
setShowAction
Sets the value of the property showAction.- Property description:
- Specifies the action to perform when a valid MouseEvent occurs.
By default, calls
MFXPopup.show(Node, double, double)with the MouseEvent screen coordinates.
-