views:

60

answers:

2

I want to build a TreeModel from some Lists that contain the source data. Now, there's an utility class called DynamicUtilTreeNode that can be used to build trees from arrays, Vectors and Hashtables, but... not from Lists?! Of course I could use the List's toArray() method, but it gives a clone array of the List's state at the moment, so any changes in the List wouldn't get propagated to the TreeModel.

Is there an obvious reason why DynamicUtilTreeNode doesn't support Lists? Is there anything similar that would support Lists, or should I just write it myself?

+1  A: 

Is there an obvious reason that DynamicUtilTreeNode doesn't support Lists?

It looks as though DynamicUtilTreeNode was written before or around the time when the List Collections framework was introduced in Java 1.2. The Collections that are supported (Vector and Hashtable) are those that needed to be retrofitted to the List interface. You will notice that JTable, as well, makes use of Vector and of Object arrays in it quick-start constructors.

s there anything similar that would support Lists, or should I just write it myself?

I dont see anything within the JDK that replaces it with a List compatible version. You might be best served rolling your own. At the very least, it may give you a better understanding of how the TreeNode objects are used.

akf
+2  A: 

GlazedLists contains everything to build a dynamic tree from lists which automatically updates as you change the lists.

Aaron Digulla