Tuesday, 27 August 2013

xml to JTree with Xstream, Nodenames lost, Java

xml to JTree with Xstream, Nodenames lost, Java

I serialize a JTree with Xstream but all Nodenames in the xml-file are
lost. The Nodes are custom objects with a toString methode. In my programm
the Tree works fine. I tested the serialization and serialisation with
nodes of the type string, no problems.
How can i serialize a JTree object with custom object nodes to xml?
This is how my tree is build:
JTree tree = new JTree();
tree.setRootVisible(false);
tree.setExpandsSelectedPaths(true);
DefaultMutableTreeNode project = new DefaultMutableTreeNode(this);
DefaultTreeModel treeModel = new DefaultTreeModel(project, true);
DefaultMutableTreeNode task = new DefaultMutableTreeNode(new
C_Task("Task"));
DefaultMutableTreeNode entry = new DefaultMutableTreeNode(new
entry("entry1"));
project.add(task);
task.add(entry);
tree.setModel(treeModel);
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);

No comments:

Post a Comment