Top Description Inners Fields Constructors Methods
one.jpro.platform.utils

public Class TreeShowing

extends Object
Class Inheritance
Imports
javafx.beans.property.BooleanProperty, .SimpleBooleanProperty, javafx.beans.value.ChangeListener, javafx.scene.Node, .Scene, javafx.stage.Window

The TreeShowing class provides access to the internal "treeShowing" property of JavaFX Nodes. This property is essential for determining whether a Node is currently part of the scene graph and actively being displayed.

In JavaFX, a Node eligible for garbage collection might still be retained in memory due to ongoing animations or background tasks. The internal "treeShowing" property tracks the visibility and usage of each Node, but it is not exposed through the standard JavaFX API. The TreeShowing class bridges this gap, enabling developers to monitor a node's lifecycle and manage resources effectively to prevent memory leaks.

By utilizing the TreeShowing class, developers can:

This facilitates the creation of robust, memory-efficient JavaFX applications by ensuring that unused nodes do not retain unnecessary resources.

Example Usage:

import javafx.animation.Timeline;
import javafx.scene.Node;

public class Example {
    public void setupNode(Node myNode) {
        // Create a Timeline animation
        Timeline myTimeline = new Timeline();
        myTimeline.setCycleCount(Timeline.INDEFINITE);

        // Obtain the TreeShowing instance for the node
        TreeShowing treeShowing = TreeShowing.treeShowing(myNode);

        // Add a listener to respond to changes in the treeShowing property
        treeShowing.addListener((observable, oldValue, showing) -> {
            if (showing) {
                // Start the animation when the node is part of the scene graph
                myTimeline.play();
            } else {
                // Stop the animation when the node is removed from the scene graph
                myTimeline.stop();
            }
        });

        // Immediately start the animation if the node is already showing
        if (treeShowing.get()) {
            myTimeline.play();
        }
    }
}

In this example, the listener monitors the "treeShowing" property of myNode. When myNode is added to the scene graph, the animation starts. Conversely, when myNode is removed, the animation stops, ensuring that resources are managed efficiently.

Author
Florian Kirmaier

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private static final Object

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static boolean
public static BooleanProperty
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

KEY_TREE_SHOWINGback to summary
private static final Object KEY_TREE_SHOWING

Constructor Detail

TreeShowingback to summary
public TreeShowing()

Method Detail

isTreeShowingback to summary
public static boolean isTreeShowing(Node node)
treeShowingback to summary
public static BooleanProperty treeShowing(Node node)
one.jpro.platform.utils back to summary

private Class TreeShowing.TreeShowingProperty

extends SimpleBooleanProperty
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv Scene
pack-priv Window

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Inherited from javafx.beans.property.SimpleBooleanProperty:
getBeangetName

Field Detail

sceneback to summary
pack-priv Scene scene
windowback to summary
pack-priv Window window

Constructor Detail

TreeShowingPropertyback to summary
pack-priv TreeShowingProperty(Node node)