Add an expand button to a JTree node that has no children?

I would like to add the expand button to my JTree nodes to indicate that they are extensible. The trick is that they don't have children until the user clicks on them (due to processing that happens in the background).

Is there a way to set node as a parent or have children without children?

thanks

+4
source share
2 answers

It is possible to use your own isLeaf() implementation of the isLeaf() override:

Returns true if this node has no children.

Swing Tutorial: JTree explains this in Section 4.1 of the Dynamic Tree.

+6
source

You have a fake child / child counter and replace it with real children using TreeWillExpandListener

+1
source

Source: https://habr.com/ru/post/1304491/


All Articles