This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Jtree change a node 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 "Jtree change a node" Watch "Jtree change a node" New topic

Jtree change a node

Mike Brooks

Joined: Oct 07, 2007
Posts: 14

I am writing a program that display a Jtree and in doing so i would like to change the name of the node from file to a string. The reason i make it a file in the first place is so that it give me the folder icon if it is a directory etc.. The problem is i don t want to show the full file path in the Jtree so I change the name of the node but when i do this the icon can change as the name is no longer a file.

Is there a way to lock the DefaultTreeCellRenderer so that node does not change or is there a better way to change the name so that the DefaultTreeCellRenderer does not change the icon

Please any help would be much appreciated.
Andre Uhres

Joined: Nov 23, 2008
Posts: 23
We use a custom cell renderer, something like this:
Alan Brooks

Joined: Nov 30, 2008
Posts: 14
You can then use the toString() menthod on the userObject and make a file to check if it is a file instead of referencing the Object
I agree. Here's the link:
subject: Jtree change a node
Similar Threads
collapsing JTree
JTree leaf
JTree and Icon