• Post Reply Bookmark Topic Watch Topic
  • New Topic

Tree Serialization How to???

 
Venkateswaran VelRajan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For my application I am using JTree to hold hierarchy of information. For each of the node I have stored the userobject as hashtable.
The TreeComponent is placed in a one side of JSplitPane.
From the forum, I try to save Tree information by serialize the TreeModel of the Tree.I don't come across any exception for my code...
I have a pblm in get back the deserialized tree in an viewable format.

To load saved Tree.......

public void load(String fileName,JTree Tree)
{
/* Input Args...
filename -- Name of the file contains serialized object
Tree -- Tree Reference where the filecontent should be
copied..
*/
DefaultTreeModel Tree_Model;
ObjectInputStream ois;
Tree_Model=null;

try
{
ois= new ObjectInputStream(new FileInputStream(FileName));
Tree_Model=(DefaultTreeModel) ois.readObject();
ois.close();
}
catch(ClassNotFoundException ioe)
{
System.out.println("\n Can\'t able to load saved Tree - ClassNotFoundException\n Exception\n"+ioe);
}
catch(IOException ioe)
{
System.out.println("\n Can\'t able to open the Tree - IOException\n Exception\n"+ioe);
}

DefaultMutableTreeNode Last_Node=null;
DefaultMutableTreeNode Root_Node;

TreePath Tree_Path;
JTree RefTree;
RefTree=new JTree(Tree_Model);
Root_Node=(DefaultMutableTreeNode)Tree_Model.getRoot();

TreeNode []Nodes=Tree_Model.getPathToRoot(Root_Node);
Tree_Path=new TreePath(Nodes);
RefTree.makeVisible(Tree_Path);
Tree=RefTree;
Tree.updateUI();
}

public void save(String fileName,JTree Tree)
{
/* Input Args...
filename -- Name of the file contains serialized object
Tree -- Tree Reference where the filecontent should be
copied..
*/
try
{
oos= new ObjectOutputStream(new FileOutputStream(FileName));
oos.writeObject((DefaultTreeModel)Tree.getModel() );
oos.close();
}
catch(IOException ioe)
{
System.out.println("\n Can\'t able to save the Tree\n Exception\n"+ioe);
}
}



The Problem I had is I don't encount any exception while trying to load and save the tree.
While saving I had a file created with some content..
While Trying to load the saved file no impact is made on the Panel that holds the Tree. How to make the deserialize tree shown on the panel

Expecting all ur valuable suggestions

Thanks in advance
V.Venkateswaran
[ February 23, 2005: Message edited by: Venkateswaran VelRajan ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!