Animated TreeView and nested Accordions

2019-09-08 17:42发布

问题:

I want to achive a Navigation for my application that looks like a TreeView but is animated like a TitledPane. That is, a Transition when expanding/collapsing an item for its content.

What I did so far is to nest multiple Accordions like this:

- TopAccordion
---- TitledPane
------- Accordion
----------TitledPane
----------TitledPane
----------TitledPane
---- TitledPane
------- Accordion
----------TitledPane
----------TitledPane
----------TitledPane

etc. Unfortunately, this results in same ugly transitions (notice the large gap when opening a nested TitledPane):

Is there a way to animate TreeViews and how? I couldn't find a way to do it by looking at the TreeCell/TreeItem API.

Regards, Sebastian

回答1:

I think, there exists a way to implement visual effect of opening like in Accordion/TitledPane for TreeView.

What you need to understand is the following thing :

There is a scenegraph (tree of nodes, which are shown on the scene). When you expand a treeItem, some TreeCells are added in the scenegraph, and content of the tree is reallocated. What you need - is to add animation, which will change the height of cells smoohtly, so that scenegraph engine will redraw the cells, while they have an encreasing height.

But you will have to do it be yourself. And I think, there is no direct support from TreeView or TreeCell for that.

You will find this decision working, and find, that it can be implemented for a wide range of situations, you can file an RFE in jfx-jira for animation support.