开发者

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

开发者 https://www.devze.com 2022-12-23 03:51 出处:网络
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 childre开发者_开发知识库n until the user clicks on them (due to process

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 childre开发者_开发知识库n 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


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号