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

五迷三道 提交于 2019-12-20 01:13:44

问题


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


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/2472634/add-expand-button-to-jtree-node-that-has-no-children

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!