Module MaterialFX

Class MFXPopup

All Implemented Interfaces:
MFXStyleablePopup, Styleable, EventTarget, Skinnable
Direct Known Subclasses:
MFXContextMenu, MFXTooltip

public class MFXPopup extends PopupControl implements MFXStyleablePopup
Custom and better implementation of a PopupControl.

Setting the popup's content is now easier, it is animated (can be disabled), the animation can be changed but the most important features are the hover property and PseudoClass ("popup-hover" in css) that specifies when the mouse is on the content, and the new show methods that make use of HPos and VPos to compute the position for you, no more x and y computation, leave it to MFXPopup.

Of course if needed JavaFX's methods are still available.

Also allows to reposition the popup on demand by calling reposition() and also offers a new EventType.

Now implements MFXStyleablePopup to make the popup customizable with CSS. Please check the interface's documentation on how to use the functionality.
  • Property Details

    • content

      public ObjectProperty<Node> contentProperty
      Specifies the popup's content.

      As of now changing the content while the popup is shown won't have any effect. For it to work, the popup must be closed and reopened again. As of now, there's no plan to improve this because such use case would introduce an unnecessary layer of complexity and in my opinion it's also a discouraged practice to change the popup's content while open. It would be better to use a container Pane and change its content.

      This is a property because when the content changes it's needed to add the necessary handlers to it to make the "hover" feature work.

      The content cannot be null.
      See Also:
    • hover

      public ReadOnlyBooleanProperty hoverProperty
      Specifies if the mouse is on the popup's content.
      See Also:
  • Constructor Details

    • MFXPopup

      public MFXPopup()
    • MFXPopup

      public MFXPopup(Node content)
  • Method Details

    • show

      public void show(Node ownerNode, double anchorX, double anchorY)
      Overrides:
      show in class PopupWindow
    • show

      public void show(Node node)
      Shows the popup at the BOTTOM_RIGHT of the specified node.

      Calls show(Node, Alignment, double, double).
    • show

      public void show(Node node, Alignment alignment)
      Shows the popup at the given positions.

      Calls show(Node, Alignment, double, double).
    • show

      public void show(Node node, Alignment alignment, double xOffset, double yOffset)
      Shows the popup at the given positions, then shifts the computed coordinates by the given offsets.

      Once the position is computed, it is stored in a PopupPositionBean alongside other useful info. These info are important because before the popup is actually shown, its skin is created. The MFXPopupSkin uses these info to properly position and animate the popup. This is needed because before creating the skin the content is not laid out so its sizes/bounds are 0 and the "real" coordinates cannot be computed. For this reason, the coordinates stored in the position bean are not reliable, because they do not take into account the adjustments applied by the skin. (as of now, maybe will be improved in the future)
    • reposition

      public void reposition()
      Repositions the popup by recomputing the position from the previous stored info.

      This should be called when the owner's position changes.

      This is also responsible for fixing the coordinates if the popup would end outside the screen
      See Also:
    • computePosition

      public PopupPositionBean computePosition()
      Used to compute the new position of the popup when repositioning.
    • hide

      public void hide()

      Overridden to set the stored PopupPositionBean to null.
      Overrides:
      hide in class PopupWindow
    • createDefaultSkin

      protected Skin<?> createDefaultSkin()
      Overrides:
      createDefaultSkin in class PopupControl
    • getPopupStyleableParent

      public Parent getPopupStyleableParent()
      Specified by:
      getPopupStyleableParent in interface MFXStyleablePopup
      Returns:
      the node that has the necessary stylesheets to customize the popup
    • setPopupStyleableParent

      public void setPopupStyleableParent(Parent parent)
      Description copied from interface: MFXStyleablePopup
      Sets the node that has the necessary stylesheets to customize the popup.
      Specified by:
      setPopupStyleableParent in interface MFXStyleablePopup
    • getStyleableParent

      public Styleable getStyleableParent()
      Specified by:
      getStyleableParent in interface Styleable
      Overrides:
      getStyleableParent in class PopupControl
    • getStyleSheets

      public ObservableList<String> getStyleSheets()
      Specified by:
      getStyleSheets in interface MFXStyleablePopup
      Returns:
      the parsed stylesheets
    • getUserAgentStylesheet

      public String getUserAgentStylesheet()
      Description copied from interface: MFXStyleablePopup
      This method works just like Region.getUserAgentStylesheet().

      Any MFXStyleablePopup should 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 here MFXContextMenuSkin).
      Specified by:
      getUserAgentStylesheet in interface MFXStyleablePopup
    • fixPosition

      public static void fixPosition(MFXPopup popup, boolean fix)
      Tells the given popup to recompute its position if it would end outside the screen.
    • isFixPosition

      public static boolean isFixPosition(MFXPopup popup)
      Returns:
      whether the given popup is configured to reposition itself if ending outside the screen
    • getPosition

      public PopupPositionBean getPosition()
      Returns:
      the instance of the PopupPositionBean computed when showing or repositioning the popup. Note that it will return null if the popup is not showing.
    • getContent

      public Node getContent()
      Gets the value of the property content.
      Property description:
      Specifies the popup's content.

      As of now changing the content while the popup is shown won't have any effect. For it to work, the popup must be closed and reopened again. As of now, there's no plan to improve this because such use case would introduce an unnecessary layer of complexity and in my opinion it's also a discouraged practice to change the popup's content while open. It would be better to use a container Pane and change its content.

      This is a property because when the content changes it's needed to add the necessary handlers to it to make the "hover" feature work.

      The content cannot be null.
    • contentProperty

      public ObjectProperty<Node> contentProperty()
      Specifies the popup's content.

      As of now changing the content while the popup is shown won't have any effect. For it to work, the popup must be closed and reopened again. As of now, there's no plan to improve this because such use case would introduce an unnecessary layer of complexity and in my opinion it's also a discouraged practice to change the popup's content while open. It would be better to use a container Pane and change its content.

      This is a property because when the content changes it's needed to add the necessary handlers to it to make the "hover" feature work.

      The content cannot be null.
      See Also:
    • setContent

      public void setContent(Node content)
      Sets the value of the property content.
      Property description:
      Specifies the popup's content.

      As of now changing the content while the popup is shown won't have any effect. For it to work, the popup must be closed and reopened again. As of now, there's no plan to improve this because such use case would introduce an unnecessary layer of complexity and in my opinion it's also a discouraged practice to change the popup's content while open. It would be better to use a container Pane and change its content.

      This is a property because when the content changes it's needed to add the necessary handlers to it to make the "hover" feature work.

      The content cannot be null.
    • getAnimationProvider

      public BiFunction<Node,Scale,Animation> getAnimationProvider()
      Returns:
      the function used by the skin to produce the popup's animation
    • setAnimationProvider

      public void setAnimationProvider(BiFunction<Node,Scale,Animation> animationProvider)
      Sets the function used by the skin to produce the popup's animation.

      The input parameters are the popup's container (it's a StackPane, and the Scale transform applied to the container.

    • isAnimated

      public boolean isAnimated()
      Specifies whether tha popup's is animated.
    • setAnimated

      public void setAnimated(boolean animated)
    • isHover

      public boolean isHover()
      Gets the value of the property hover.
      Property description:
      Specifies if the mouse is on the popup's content.
    • hoverProperty

      public ReadOnlyBooleanProperty hoverProperty()
      Specifies if the mouse is on the popup's content.
      See Also:
    • setHover

      protected void setHover(boolean hover)
      Sets the value of the property hover.
      Property description:
      Specifies if the mouse is on the popup's content.