Add to the Tree same values to b displayed as leaves


i need to compose a Tree object holding some same nodes. how can i do this? As far as i understand when i call the
addItem(…) method i pass some String to display as node title. Some object (of the Item type) it returned but i can’t use it to establish parent-child relations between nodes. So how can i distinguish the nodes w/ the same values in them?

Thanks for your assist.


You have to use the item id (as oposed to the item itself). As you can see:

Item addItem(java.lang.Object itemId) This method returns an
and you pass an
. What you have to do is something like this:

tree.addItem("value 1");
tree.addItem("value 2");
tree.setParent("value 2", "value 1");

Hi Alejandro!
Thanks for your reply. Let’s assume i need to insert the same values and make one of them parent for another. is the following will b a good solution 4 this?

tree.addItem("value 1"); tree.addItem("value 1"); tree.setParent("value 1", "value 1"); If not - than how can i achieve this? For more real-life case consider the situation when items w/ the same labels located in the different subtrees of the original tree.


In that case can set the captions for each item. For example:

tree.addItem("parent"); tree.addItem("child"); tree.setParent("child", "parent"); tree.setItemCaption("parent", "value 1"); tree.setItemCaption("child", "value 1"); So
are the items IDs, and
“value 1”
is used as caption for both items.