【问题标题】:How to make a any node as parent node in JTree so that children can be added to it?如何在 JTree 中将任意节点设为父节点,以便将子节点添加到其中?
【发布时间】:2011-02-18 10:08:56
【问题描述】:

如何将 JTree 中的当前节点设为父节点,以便向其添加子节点。我的完整数据是从数据库中获取的。

有点像下面:

root-- parent1 - children
    |- parent2 - children

我需要动态生成树

提前致谢:)

【问题讨论】:

    标签: java swing jtree


    【解决方案1】:

    如果您的节点是 MutableTreeNode,例如DefaultMutableTreeNode 使用

    public void insert(MutableTreeNode newChild, int childIndex) 
    

    将子节点添加到当前节点的方法

    【讨论】:

      【解决方案2】:

      构造树的常用方法是构造DefaultMutableTreeNode 实例的层次结构。这个类有一个add(MutableTreeNode newChild) 方法,允许向现有节点添加一个子节点。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-08-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-12-29
        • 1970-01-01
        • 2023-03-30
        相关资源
        最近更新 更多