My program is importing a DefaultTreeModel from another program. In my program, I would like to create an identical DefaultTreeModel, but instead of each node being a DefaultMutableTreeNode, I would like each to be a simContainerNode (which is a class I wrote that extends DefaultTreeModel that has the additional field of int frequency).
Does anyone have a good way of doing this? Or even any ideas? I am absolutely stumped.
Just write some code which goes through the source tree recursively and produces the target tree as you go along. Basically you'd have a method "private simContainerNode copyNode(DefaultMutableTreeNode node)" which creates the new node from the old one and then appends copies of the old node's children (created by that method) to the new node.
(Instead of extending DefaultMutableTreeNode you might consider the fact that you can put any kind of object at all into it as the user object.)
posted 9 years ago
Thanks for your help. I got it working by basically doing exactly what you said, and "swallowing" the old tree's nodes into the new ones by storing the old nodes as the user object in the new ones.
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database