从已保存的文件重新加载JTree

时间:2013-02-05 16:43:43

标签: java swing reload jtree defaulttreemodel

我从一个文件中读取了一个JTree。我想在我的JPanel中显示它。 我在读取文件后重新加载DefaultTreeModel,但它不起作用。

public class DynamicTree extends JPanel 
{
    protected   myDefaultMutableTreeNode rootNode;
    protected   DefaultTreeModel treeModel;
    protected   JTree tree;
    private transient  Toolkit toolkit = Toolkit.getDefaultToolkit();
    private      URL helpURL;

    public void reloadModel(){this.treeModel.reload();}
}

阅读文件以加载DynamicTree

address = (DynamicTree) ReadDynamicTreeFromFile();

 MainPanel.SetTree4load(address);

SetTree4load(地址)方法是:

 public static void SetTree4load(DynamicTree tree)
    {
         treePanel=tree;       //treepanel is the current DynamicTree in the frame
         treePanel.reloadModel();
    }

提前致谢:)

1 个答案:

答案 0 :(得分:1)

而不是改变树。尝试将模型和数据模型从加载的树设置为面板树