JTree Model design problem

I need to create a JTree view for a hierarchy of classes. Hiearchy is based on "Group"s, which contain child Groups and "Item"s. Group and Item classes are from my model. How can I build a TreeModel having both types of elements? All JTree customization examples are based on single type of objects. Any ideas?

[317 byte] By [funkysa] at [2007-11-26 15:33:29]
# 1

Did not clearly get what you meant in the post... Still trying with what i understand.. dont mind if its absurd ;)

Define user objects by overriging DefaultMutableTreeNode.. model methods has generic signature as DMT or TreeNode.. so there should not be any problem in having a model with different types of object for various types of tree nodes...

ganeshaa8a at 2007-7-8 21:50:38 > top of Java-index,Desktop,Core GUI APIs...
# 2
Read the tutorial there is an example there how to use existing data structure. http://java.sun.com/docs/books/tutorial/uiswing/components/tree.html#data
Rodney_McKaya at 2007-7-8 21:50:38 > top of Java-index,Desktop,Core GUI APIs...
# 3

I think what I need is the Composite pattern. DefaultMutableTreeNode does not do what I want. That way, Group : DefaultMutableTreeNode has references to Item's, but not to subGroups.

class Group {

vector<Group> subgroups;

vector<Item> items; // no - I don't want this.

}

class Item {

}

-

class Group implements Component {

vector <Component> children;

}

class Item implements Component {

}

--

You mean use DefaultMutableTreenode as Component.. Am I right? That would be an answer.

Thank you.

funkysa at 2007-7-8 21:50:38 > top of Java-index,Desktop,Core GUI APIs...