我从一个文件中读取了一个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();
}
提前致谢:)
答案 0 :(得分:1)
而不是改变树。尝试将模型和数据模型从加载的树设置为面板树