• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Jtree problem

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
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"))
setForeground(Color.blue);
else
setForeground(Color.red);
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?
Thanks
 
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Change

add more if statement and that should do the job for you
Thank you
Garandi
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic