public class myMutableTreeNode extends DefaultMutableTreeNode
{
// tree nodes rendered as JTable
}
public myWin extends Jframe()
{
// constructor
top = new myMutableTreeNode();
jTree1=new JTree(top);
..................................
// nodes are added to tree and rendered as jtable
// On “save” menu option, I want to save this Jtree1 using XML and later retrieve on “open” command.
if (e.getActionCommand() == "Save")
{
XMLEncoder encoder = new XMLEncoder( new BufferedOutputStream(new FileOutputStream( "sample.xml" ) ));
DefaultTreeModel c = (DefaultTreeModel)jTree1.getModel();
encoder.writeObject(c);
encoder.close();
}
}
But it did not work as I expected. Will anybody say what I am doing wrong and help to solve this problem?
Thanks.