Re: can JTree's have multiple roots and models ?
- From: "Oliver Wong" <owong@xxxxxxxxxxxxxx>
- Date: Thu, 27 Oct 2005 20:53:07 GMT
"William Z." <Wizumwalt@xxxxxxxxx> wrote in message
news:1130432224.977075.119930@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
>
>>
>> Similarly, take all your TreeModels and make them children of a
>> "super-TreeModel", and make that the model for your JTree.
>>
>> - Oliver
>
> Not sure I follow this idea, I didn't think models could have models,
> unless you meant to make my own super model to manage it's children
> models.
>
I meant you could have a main "super" TreeModel delegate most of the
work to your other TreeModels, with the super TreeModel mainly dealing with
creating the illusion that all of those sub-models are part of a bigger
tree. Here's an example implementation:
<code>
public SuperTreeModel implements TreeModel {
private final ArrayList<TreeModel> subTreeModels;
public SuperTreeModel(ArrayList<TreeModel> subTreeModels) {
this.subTreeModels = subTreeModels;
}
public Object getRoot() {
return this;
}
public Object getChild(Object parent, int index) {
if (parent == this) {
return subTreeModels.get(index).getRoot();
}
/* Otherwise you have to figure out which TreeModel the parent came
from, and then delegate the call appropriately. You might have to have
control over the subTreeModels to do this, and add a "containsNode()" method
in them.
*/
}
/* Etc. for the other methods. */
}
</code>
- Oliver
.
- Follow-Ups:
- Re: can JTree's have multiple roots and models ?
- From: Thomas Hawtin
- Re: can JTree's have multiple roots and models ?
- References:
- can JTree's have multiple roots and models ?
- From: William Z.
- Re: can JTree's have multiple roots and models ?
- From: Oliver Wong
- Re: can JTree's have multiple roots and models ?
- From: William Z.
- can JTree's have multiple roots and models ?
- Prev by Date: Re: problem using html for multiline jbutton
- Next by Date: Re: can JTree's have multiple roots and models ?
- Previous by thread: Re: can JTree's have multiple roots and models ?
- Next by thread: Re: can JTree's have multiple roots and models ?
- Index(es):