View Full Version : GXT 3.0 Tree - How to display custom icon per tree node?

20 Dec 2011, 11:28 AM
I need to display a multi-level tree and show various icons per tree node. In the demo examples all I see are images set at the root tree level, i.e. one TreeStyle for the entire tree. How can I display different icons at each of the tree nodes/levels?

20 Dec 2011, 4:59 PM
Looks like you need to implement an IconProvider and pass it to the Tree.

21 Dec 2011, 3:54 AM
tree.setIconProvider(new IconProvider<SideMenuDto>() {

public ImageResource getIcon(SideMenuDto p_model) {
return .... // your icon choosing algorithm

where SideMenuDto is my tree item object. Use your own in your case.

21 Dec 2011, 10:51 AM
Yeah that works perfectly, plus I found I can dynamically update the icons which is what I need to do by calling refresh on the tree. Thanks.

8 Nov 2013, 2:41 AM
Digging out an old thread.

I managed to use IconProvider to display a different icon for various tree nodes. Is there a way to set a different open and close icon for the various tree nodes type?

Colin Alworth
8 Nov 2013, 9:02 AM
The open and close nodes are governed by one of two things:
* First, check to see if a TreeStyles object was set via setStyle
* Second, use the appearance instance that the tree was given

10 Nov 2013, 7:18 PM
Currently I can only use either TreeStyle to display the nodes icons with either open/close or use IconProvider to display them with my different node types. So you are saying if I want to combine the two, I have to use TreeAppearance?