aspose file tools
The moose likes Swing / AWT / SWT and the fly likes How to set Icons in the JTree Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to set Icons in the JTree" Watch "How to set Icons in the JTree" New topic

How to set Icons in the JTree

William Flores
Ranch Hand

Joined: Dec 14, 2011
Posts: 30

Hi guys!

I have a problem here. I'm implementing a JTree, but now I need set icons in each node.
I have searched about this, but I don't undestand very well how to do this.
Can someone help me? Please!
Nitin Surana
Ranch Hand

Joined: Jan 21, 2011
Posts: 129

All you need is a TreeCellRender.

I have posted a very simple example for you here
Rob Spoor

Joined: Oct 27, 2005
Posts: 20041

There's no need to override DefaultTreeCellRenderer. It has its own methods to set the icons for opened nodes, closed nodes and leaf nodes. Just create an instance, set the right icons, and set that instance as the renderer.

How To Ask Questions How To Answer Questions
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: How to set Icons in the JTree
It's not a secret anymore!