Meaningless Drivel is fun!*
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 Android Security Essentials Live Lessons 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
Author

How to set Icons in the JTree

William Flores
Greenhorn

Joined: Dec 14, 2011
Posts: 29

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

http://www.onlinexamples.com/showfullexample.action?idexamples=82&title=Jtree%20Nodes%20With%20Icon%20-%20Treecellrenderer
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to set Icons in the JTree
 
Similar Threads
JTree
Jtree multiple icons
Different Icons for JTree
JTree
JTree