Class TreeShowing
java.lang.Object
com.dlsc.gemsfx.util.TreeShowing
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 TypeMethodDescriptionstatic booleanisTreeShowing(javafx.scene.Node node) Convenience method that checks the current state without creating a long-lived property object.static javafx.beans.property.BooleanPropertytreeShowing(javafx.scene.Node node) Returns the cachedtreeShowingproperty fornode, creating it on first access.
-
Method Details
-
treeShowing
public static javafx.beans.property.BooleanProperty treeShowing(javafx.scene.Node node) Returns the cachedtreeShowingproperty fornode, creating it on first access.- Parameters:
node- the node to observe; must not benull- Returns:
- a
BooleanPropertythat 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 benull- Returns:
trueif the node is attached to a showing window
-