thedude19
thedude19

Reputation: 2673

Add 'expand' button to JTree node that has no children?

I'd like to add the 'expand' button to my JTree's nodes to indicate that they are expandable. The catch is that they have no children until the user clicks on them (due to processing that happens in the background).

Is there any way I can set a node as a parent or having children without it actually having children?

Thanks

Upvotes: 4

Views: 2673

Answers (2)

Peter Lang
Peter Lang

Reputation: 55514

It's possible using your own DefaultMutableTreeNode implementation overriding isLeaf():

Returns true if this node has no children.

Swing Tutorial: JTree explains it under 4.1 Dynamic Tree.

Upvotes: 7

Eugene Ryzhikov
Eugene Ryzhikov

Reputation: 17359

Have a fake child/child count and replace it with real children using TreeWillExpandListener

Upvotes: 1

Related Questions