wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes custom JTree icons Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "custom JTree icons" Watch "custom JTree icons" New topic
Author

custom JTree icons

Alan Shiers
Ranch Hand

Joined: Sep 24, 2003
Posts: 237
Hi there,
I'm trying to do a small project where I can display my own icons in a JTree. However, when I attempt to run the code below the icons don't get displayed. I've tried various combinations of code all resulting the same, no icons.
Please look over my code and tell me where I went wrong.
Thanks,
Alan

[ October 14, 2003: Message edited by: Michael Ernest ]
Michael Ernest
High Plains Drifter
Sheriff

Joined: Oct 25, 2000
Posts: 7292

I'll move this to the Swing forum where you're bound to get a quick response.


Make visible what, without you, might perhaps never have been seen.
- Robert Bresson
sheng wang
Greenhorn

Joined: Nov 04, 2002
Posts: 4
if you get a NullPointerException?
i think:
if you can insure images/xxx.gif in you classpath
the code is right.
Tamizh Selvan
Greenhorn

Joined: Oct 10, 2003
Posts: 15
hi first check whether the image is loading properly. because if the image is not loaded or if it is not the location no error is thrown. if all r ok then try the below method.
getTreeCellRendererComponent(JTree tree,
Object value,
boolean selected,
boolean expanded,
boolean leaf,
int row,
boolean hasFocus)
override this method and check whether the node is leaf or closed or opened and then set the icon.
hope this helps u
Marcus


"No one knows what one can do until one tries"<br />-John Kingsley.
 
wood burning stoves
 
subject: custom JTree icons
 
Similar Threads
custom icons in JTree
Help with Jtree
plus/minus sign in a jtree
setting JTree icons
Empty directories are shown as leaf nodes while using JTree to display filesystem