Module MaterialFX

Class MFXStageDialog

java.lang.Object
javafx.stage.Window
javafx.stage.Stage
io.github.palexdev.materialfx.dialogs.MFXStageDialog
All Implemented Interfaces:
EventTarget

public class MFXStageDialog extends Stage
Dialog implementation that simply extends Stage.

The main purpose of this is to wrap/show AbstractMFXDialog by setting the contentProperty().

This stage dialog is also draggable with the mouse (can be enabled/disabled), can be closed when pressing on the owner node (overlay close feature), can "scrim" the owner node on open. To make these last two features work it's necessary to specify who is the owner node, setOwnerNode(Pane).

To make the scrim effect work, the show/close methods of Stage have been overridden, however the Stage.show() method is final, to properly show the dialog please use showDialog() instead.

A side note on usage:

Unfortunately in JavaFX there is still no concept of "low-weight" dialog. Even the JavaFX's default implementation is just a Stage. The issue with that is that creating Stages is a quite expensive task, cannot be done on separate threads dor whatever reason, and therefore can make the application unresponsive, even if for a short time.

So, the advice is to build this dialogs ahead of time, keep them in memory if you can, so that you can use them whenever you need and just change their content if needed,

  • Property Details

  • Constructor Details

    • MFXStageDialog

      public MFXStageDialog()
    • MFXStageDialog

      public MFXStageDialog(AbstractMFXDialog content)
  • Method Details

    • buildScene

      protected Scene buildScene(AbstractMFXDialog content)
      Builds the dialog's scene for the given content.
    • initDraggable

      protected void initDraggable()
      Enables/Disabled the draggable feature.
    • initOverlayClose

      protected void initOverlayClose()
      Enables/Disables the overlay close feature.
    • showDialog

      public void showDialog()
      Calls scrimOwner() than shows the dialog.
    • showAndWait

      public void showAndWait()
      Calls scrimOwner() then shows the dialog and waits.
      Overrides:
      showAndWait in class Stage
    • hide

      public void hide()
      Calls unScrimOwner() then closes the dialog.
      Overrides:
      hide in class Window
    • scrimOwner

      protected void scrimOwner()
      This is responsible for applying the scrim effect (if enabled) according to the getScrimPriority().
    • unScrimOwner

      protected void unScrimOwner()
      If getOwnerNode() is not null removes the scrim effect from it.
    • centerInOwner

      protected void centerInOwner()
      This is responsible for centering the dialog on the getOwnerNode() (if enabled).
    • dispose

      public void dispose()
      Disposes the dialog, making it not reusable anymore!
    • load

      public static MFXStageDialog load(Class<?> clazz, String fxmlPath) throws IOException
      Convenience method to create a MFXStageDialog from an FXML file.

      Two notes:

      - the file is loaded using the given class, so make sure the FXML file is in the right directory

      - the method expects to load a AbstractMFXDialog as root

      Throws:
      IOException
    • loadOrNull

      public static MFXStageDialog loadOrNull(Class<?> clazz, String fxmlPath)
      Same as load(Class, String), but in case of fail it will return null.
    • getContent

      public AbstractMFXDialog getContent()
      Gets the value of the property content.
      Property description:
      Specifies the dialog' scene root node.
    • contentProperty

      public ObjectProperty<AbstractMFXDialog> contentProperty()
      Specifies the dialog' scene root node.
      See Also:
    • setContent

      public void setContent(AbstractMFXDialog content)
      Sets the value of the property content.
      Property description:
      Specifies the dialog' scene root node.
    • isDraggable

      public boolean isDraggable()
      Returns:
      whether the dialog is draggable
    • setDraggable

      public void setDraggable(boolean draggable)
    • isOverlayClose

      public boolean isOverlayClose()
      Returns:
      whether the dialog will be closed when pressing on the specified getOwnerNode()
    • setOverlayClose

      public void setOverlayClose(boolean overlayClose)
    • getOwnerNode

      public Pane getOwnerNode()
      Returns:
      the node which "owns" the dialog
    • setOwnerNode

      public void setOwnerNode(Pane ownerNode)
    • isCenterInOwnerNode

      public boolean isCenterInOwnerNode()
      Gets the value of the property centerInOwnerNode.
      Property description:
      Specifies whether the dialog should be centered on the getOwnerNode() when shown.
    • centerInOwnerNodeProperty

      public BooleanProperty centerInOwnerNodeProperty()
      Specifies whether the dialog should be centered on the getOwnerNode() when shown.
      See Also:
    • setCenterInOwnerNode

      public void setCenterInOwnerNode(boolean centerInOwnerNode)
      Sets the value of the property centerInOwnerNode.
      Property description:
      Specifies whether the dialog should be centered on the getOwnerNode() when shown.
    • isScrimOwner

      public boolean isScrimOwner()
      Gets the value of the property scrimOwner.
      Property description:
      Specifies whether to scrim the getOwnerNode() when showing the dialog.
    • scrimOwnerProperty

      public BooleanProperty scrimOwnerProperty()
      Specifies whether to scrim the getOwnerNode() when showing the dialog.
      See Also:
    • setScrimOwner

      public void setScrimOwner(boolean scrimOwner)
      Sets the value of the property scrimOwner.
      Property description:
      Specifies whether to scrim the getOwnerNode() when showing the dialog.
    • getScrimStrength

      public double getScrimStrength()
      Gets the value of the property scrimStrength.
      Property description:
      Specifies the strength(opacity, so values from 0.0 to 1.0) of the scrim effect, by default it is 0.5
    • scrimStrengthProperty

      public DoubleProperty scrimStrengthProperty()
      Specifies the strength(opacity, so values from 0.0 to 1.0) of the scrim effect, by default it is 0.5
      See Also:
    • setScrimStrength

      public void setScrimStrength(double scrimStrength)
      Sets the value of the property scrimStrength.
      Property description:
      Specifies the strength(opacity, so values from 0.0 to 1.0) of the scrim effect, by default it is 0.5
    • getScrimPriority

      public ScrimPriority getScrimPriority()
      Returns:
      the enum constant used to specify how to apply the scrim effect. You can have two owners, one is the stage owner(Window) and the other is the dialog owner(Pane). Sometimes it's better to apply the scrim to the window (for example the owner node would not allow to apply the scrim effect, for example AnchorPanes, VBoxes, HBoxes...), but you still want to center the dialog in the owner node. Setting this to ScrimPriority.WINDOW will tell the dialog to apply the effect to Stage.getOwner(), setting this to ScrimPriority.NODE will tell the dialog to apply the effect to getOwnerNode().
    • setScrimPriority

      public void setScrimPriority(ScrimPriority scrimPriority)
      Sets the enum constant used to specify how to apply the scrim effect.
      See Also: