Class TreeShowing

java.lang.Object
com.dlsc.gemsfx.util.TreeShowing

public final class TreeShowing extends Object
Provides access to a derived "treeShowing" property for any Node.

JavaFX does not expose a public API that tells you whether a node is currently attached to a visible window. This class fills that gap: the BooleanProperty returned by treeShowing(Node) is true whenever the node's scene is non-null, the scene has a non-null window, and that window is showing.

A single property instance is created per node and cached in the node's property map, so repeated calls for the same node are cheap.

Typical use-case: stop animations or background services as soon as a node is removed from the scene graph, preventing memory leaks.

TreeShowing.treeShowing(myNode).addListener((obs, wasShowing, isShowing) -> {
    if (isShowing) {
        myTimeline.play();
    } else {
        myTimeline.stop();
    }
});
if (TreeShowing.isTreeShowing(myNode)) {
    myTimeline.play();
}
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    isTreeShowing(javafx.scene.Node node)
    Convenience method that checks the current state without creating a long-lived property object.
    static javafx.beans.property.BooleanProperty
    treeShowing(javafx.scene.Node node)
    Returns the cached treeShowing property for node, creating it on first access.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • treeShowing

      public static javafx.beans.property.BooleanProperty treeShowing(javafx.scene.Node node)
      Returns the cached treeShowing property for node, creating it on first access.
      Parameters:
      node - the node to observe; must not be null
      Returns:
      a BooleanProperty that reflects whether the node is part of a visible window
    • isTreeShowing

      public static boolean isTreeShowing(javafx.scene.Node node)
      Convenience method that checks the current state without creating a long-lived property object.
      Parameters:
      node - the node to check; must not be null
      Returns:
      true if the node is attached to a showing window