Update TreeNode Image or Icon
Hi,
Is it possible to update or change the image or icon associated with a treenode which already has a previous image? I have tried changing/updating and it does not work. However, changing the text of that treenode works perfectly. Is it really possible to do that in a treenode or not?
Thanks.
Regards,
eebora
[343 byte] By [
eebora] at [2007-11-26 11:24:03]

# 1
According to the Java Studio Creator Help within the IDE:
If you select the image in the Tree Node, you can see that its icon property is set to TREE_DOCUMENT. If you right-click the image on the page and choose Set Image, you can either change the icon to another one or choose your own image in the Image Customizer dialog box. For more information on working with an image in a tree node, see 'Image component' also in the Help section.
The image used in a tree node works best if it is 16x16 or smaller. Larger images can work, but might appear overlapped in the Visual Designer. You can right-click the component and choose Preview in Browser feature to check the appearance of the images.
Hope that helps,
christina
# 2
Thanks for the reply cristina.
But what I mean on my post is updating the image icon of a treenode programmatically. I was able to set the image icon of my treenode when I first created it. The problem occurs when I try to change the icon again while my application is running. I have made some investigation and I found out that the image icon property of the treenode was updated but upon display of the page (I also tried to view the source code of the rendered page), the old image icon was still being used. Thus, the image icon of the treenode was not being updated.
Thanks.
# 3
Finally I got it working.
Here's how I did it:
ImageHyperlink img = (ImageHyperlink)treeNodeSelected.getFacet("image");
img.setImageURL(newimage.gif);
It seems that when setting the image icon of a tree node using treeNode.setImageURL() method when the treenode was first created, the image facet was set properly. But once the tree node has been rendered, the image facet and treenode object are two different elements in the form. To update the image icon of a tree node, you need to get the image facet and modify from there.
I hope that using the treeNode.setImageURL() method also updates the image facet associated with it but its not. Im not sure if this is really a bug or it was designed like this. Anyway, I hope tree users (like I am) will find this very useful.
Happy coding! c",?
# 4
Just a quick note. If you plan to update your treenode image programmatically, be sure you also create the image facet manually the first time you create the treenode.
TreeNode treeNode = new TreeNode();
treeNode.setId(id);
treeNode.setText(name);
ImageHyperlink img = new ImageHyperlink();
img.setImageURL(imageURL);
treeNode.getFacets().put(TreeNode.IMAGE_FACET_KEY, img);
Most of the time, using
(TreeNode)getForm1().findComponentById(sId);
to get the treenode returns null (and I dont know why) when accessing its image facet using this command:
treeNode.getFace("image")
That's the reason I tried to find another solution which brought me to the sample code above. Hope this further helps any tree user out there.
Happy coding everyone! c",?