Module MaterialFX

Class NodeUtils

java.lang.Object
io.github.palexdev.materialfx.utils.NodeUtils

public class NodeUtils extends Object
Utility class which provides convenience methods for working with Nodes
  • Method Details

    • updateBackground

      public static void updateBackground(Region region, Paint fill)
      Changes the background color of a Region to the desired one.
      Parameters:
      region - The region to change the background color to
      fill - The desired color
    • updateBackground

      public static void updateBackground(Region region, Paint fill, Insets backgroundInsets)
      Changes the background color of a Region to the desired one and lets specify the background insets.
      Parameters:
      region - The region to change the background color to
      fill - The desired color
      backgroundInsets - The background insets to use
    • updateBackground

      public static void updateBackground(Region region, Paint fill, CornerRadii cornerRadii, Insets backgroundInsets)
    • setBackground

      public static void setBackground(Region region, Paint fill)
      Sets the background of the given region to the given color.
    • setBackground

      public static void setBackground(Region region, Paint fill, CornerRadii radius)
      Sets the background of the given region to the given color, with the given radius.
    • setBackground

      public static void setBackground(Region region, Paint fill, CornerRadii radius, Insets insets)
      Sets the background of the given region to the given color, with the given radius and insets.
    • parseCornerRadius

      public static CornerRadii parseCornerRadius(Region region)
      Tries to parse tje given Region's corner radius.

      To be more precise it tries to parse both the background and the border radius. The background radius is prioritized over the border one but in case the background is null or empty then the border one is used.

      In case of both null or empty returns CornerRadii.EMPTY.

    • centerNodeInAnchorPane

      public static void centerNodeInAnchorPane(Node node, double topBottom, double leftRight)
      Centers the specified node in an AnchorPane.
    • inHierarchy

      public static boolean inHierarchy(Node node, Node element)
      Checks if the specified element is in the hierarchy of the specified node.
    • inHierarchy

      public static boolean inHierarchy(Node node, MouseEvent event)
      Checks if the pressed node is in the hierarchy of the specified node, PickResult.getIntersectedNode().
    • inHierarchy

      public static boolean inHierarchy(MouseEvent event, Node node)
      Checks if the specified node is in hierarchy of the pressed node, PickResult.getIntersectedNode().
    • makeRegionCircular

      public static void makeRegionCircular(Region region)
      Makes the given region circular.

      Notice: the region's pref width and height must be set and be equals

      Parameters:
      region - The given region
    • makeRegionCircular

      public static void makeRegionCircular(Region region, double radius)
      Makes the given region circular with the specified radius.

      Notice: the region's pref width and height must be set and be equals

      Parameters:
      region - The given region
      radius - The wanted radius
    • getRegionHeight

      public static double getRegionHeight(Region region)
      Retrieves the region height if it isn't still laid out.
      Parameters:
      region - the Region of which to know the height
      Returns:
      the calculated height
    • getRegionWidth

      public static double getRegionWidth(Region region)
      Retrieves the region width if it isn't still laid out.
      Parameters:
      region - the Region of which to know the width
      Returns:
      the calculated width
    • getNodeHeight

      public static double getNodeHeight(Node node)
      Retrieves the node height if it isn't still laid out.
      Parameters:
      node - the Node of which to know the height
      Returns:
      the calculated height
    • getNodeWidth

      public static double getNodeWidth(Node node)
      Retrieves the node width if it isn't still laid out.
      Parameters:
      node - the Node of which to know the width
      Returns:
      the calculated width
    • getNodeSizes

      public static SizeBean getNodeSizes(Node node)
      Retrieves the node's width and height if it isn't still laid out
      Parameters:
      node - the Node of which to know the sizes
      Returns:
      the computed width and height as a SizeBean
    • addPrefWidth

      public static void addPrefWidth(Region region, double value)
      Convenience method for adding the desired value to the region's prefWidth
    • addPrefHeight

      public static void addPrefHeight(Region region, double value)
      Convenience method for adding the desired value to the region's prefHeight
    • fireDummyEvent

      public static void fireDummyEvent(Node node)
      Convenience method for programmatically fire a dummy MOUSE_PRESSED event on the desired node.
    • isRightAlignment

      public static boolean isRightAlignment(Pos alignment)
      Checks if the given alignment is set to RIGHT(any).
    • getAllNodes

      public static ArrayList<Node> getAllNodes(Parent root)
      Recursively gets all nodes that are descendants of the given root.
    • waitForSkin

      public static void waitForSkin(Control control, Runnable action, boolean addListenerIfNotNull, boolean isOneShot)
      Convenience method to execute a given action after that the given control has been laid out and its skin is not null anymore.

      If the skin is not null when called, the action is executed immediately.

      The listener is added only if the skin is null or the addListenerIfNotNull parameter is true.

      Parameters:
      control - the control to check for skin initialization
      action - the action to perform when the skin is not null
      addListenerIfNotNull - to specify if the listener should be added anyway even if the scene is not null
      isOneShot - to specify if the listener added to the skin property should be removed after it is not null anymore
    • waitForScene

      public static void waitForScene(Node node, Runnable action, boolean addListenerIfNotNull, boolean isOneShot)
      Convenience method to execute a given action after that the given node has been laid out and its scene is not null anymore.

      If the scene is not null when called, the action is executed immediately.

      The listener is added only if the scene is null or the addListenerIfNotNull parameter is true.

      Parameters:
      node - the node to check for scene initialization
      action - the action to perform when the scene is not null
      addListenerIfNotNull - to specify if the listener should be added anyway even if the scene is not null
      isOneShot - to specify if the listener added to the scene property should be removed after it is not null anymore
    • isPseudoClassActive

      public static boolean isPseudoClassActive(Control control, PseudoClass pseudoClass)
      Checks if the given PseudoClass is currently active on the given Control.
    • getScreenFor

      public static Screen getScreenFor(Node node)
      Attempts to get the Screen instance on which the given Node is shown. If the screen is not found for any reason, returns null.