简体   繁体   中英

Reloading a JTree from a saved file

I read a JTree from a file. I want to show it in my JPanel. I reload the DefaultTreeModel after reading the file but, it doesn't work.

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();}
}

Read the file for loading DynamicTree

address = (DynamicTree) ReadDynamicTreeFromFile();

 MainPanel.SetTree4load(address);

The SetTree4load(address) method is:

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

Thanks in advance :)

Instead of changing the tree. Try to set the model and the datamodel from the loaded tree to the panel tree

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM