Take a look at this; I found a search on the Internet. I found here after googling "javafx TreeView animation".
Well, therefore, after spending several minutes studying the code, I realized that the important part of the code is this:
rootItem.expandedProperty().addListener(new ChangeListener<Boolean>() { public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) { new Timeline( new KeyFrame(Duration.seconds(0), new KeyValue(tree.opacityProperty(), 0)), new KeyFrame(Duration.seconds(1), new KeyValue(tree.opacityProperty(), 1.0)) ).play(); } });
This code adds a listener that runs code that executes the required animation every time rootItem.expandedProperty() changes, i.e. the user expands or collapses the tree.
Each time something triggers a change in expandedProperty , it creates a new Timeline object, which I assume is the actual steps in a particular animation. The current code changes the opacity of the tree, causing the rootItem subtree rootItem โdisappearโ for 1 second.
To implement a separate animation to close the tree, you can use the parameters of the changed method in the listener to distinguish between two cases.
For such an animation to occur with each subtree, such a listener must be added to each node in the tree with children. Enumerating all the elements of a tree is an extremely simple operation that you learned when you studied data structures, so I donโt need to understand exactly how to do this.
However, if the fade animation is not good enough for your application, I would suggest using a nested accordion, for example this question . Of the only elements you give, an accordion will be the best way to show staff lists anyway.