Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想将“展开”按钮添加到我的 JTree 节点以表明它们是可展开的。问题是,在用户点击它们之前,它们没有孩子(由于在后台进行的处理)。
有什么方法可以将节点设置为父节点或有子节点而实际上没有子节点?
谢谢
可以使用您自己的DefaultMutableTreeNode实现覆盖isLeaf():
DefaultMutableTreeNode
isLeaf()
如果此节点没有子节点,则返回 true。
Swing 教程:JTree在4.1 动态树下解释它。
使用 TreeWillExpandListener 有一个假的孩子/孩子计数并用真正的孩子替换它