File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Jtree problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Jtree problem" Watch "Jtree problem" New topic

Jtree problem

Tal Go

Joined: Oct 22, 2003
Posts: 1
I had a problem coloring a specific node in a jtree, because it was coloring the entire nodes in the tree.
Then i found out through this forum how to paint only the nodes that i want
using the code bellow:
jTree1.setCellRenderer(new DefaultTreeCellRenderer() {
public Component getTreeCellRendererComponent(JTree tree,
Object value, boolean sel, boolean expanded,
boolean leaf, int row, boolean hasFocus) {
super.getTreeCellRendererComponent(tree, value,
sel, expanded, leaf, row, hasFocus);
if (((DefaultMutableTreeNode)value).getUserObject().toString().equals("blue node"))
return this;
it works great, the only problem is that the tree renderer updates the colors in case of a change.
for example if i have a node who's object is a String "blue node",
if i change this string to something else, it will automaticly change its
color to red, and i dont want that to happen.
anyone knows how can it be done?
Garandi Garandi
Ranch Hand

Joined: Jan 07, 2003
Posts: 192

add more if statement and that should do the job for you
Thank you
I agree. Here's the link:
subject: Jtree problem
It's not a secret anymore!