This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
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 Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "custom JTree icons" Watch "custom JTree icons" New topic

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.

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

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

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

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

"No one knows what one can do until one tries"<br />-John Kingsley.
I agree. Here's the link:
subject: custom JTree icons
It's not a secret anymore!