• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Jtree Ugly Look

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I am having problem with JTree, i have changed the background tree color to pink and when i expand any tree, it creates a white box equal to the size tree expanded, how should I prevent this so that the background color remains pink.
regards,
Nelson
 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
On what platform are you running? (I have seen funky color behavior on some Unices.)
Bill

pink?!
 
Nelson David
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using Win2000, I think its not the platform problem, the entire portion that turn white must be turn into the color of background(pink) rather then white.
Hopes for a good reply that solves my problem.
Nelson.
 
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JTree seems to be opaque as JLabels are (I mean, their background is transparent). either you make them opaque, using setOpaque(boolean) or you change the background of the underlying component.
(if changing the opaque state seems not to work, I might have gotten it wrong, and opaque means that it's not transparent, than set it opaque instead.)
chantal
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want all your JTrees in your application to look this way ( or if there is only one, and you don't care.) There is a really simple way to do this... Change the colors used by the UIManager for trees!

Before you show your tree, put new Color values into the UIManager... The keys you will probably be most interested in are:

Tree.background
Tree.foreground
Tree.selectionBackground
Tree.selectionBorderColor
Tree.selectionForeground
Tree.textBackground
Tree.textForeground

You can use them like this...

 
Nelson David
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot Nathan I got my problem solved.
Nelson
 
Nelson David
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nathan is there a way to change the color of tree node?
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not sure what you mean by "node"? Do you mean each entry in the tree?

The "Tree.textBackground" and "Tree.textForeground" properties control the background and foreground colors of the tree entries... but it does so for all tree entries. If you need different entries to have different colors, you will need to make a new TreeCellRenderer (probably by extending DefaultTreeCellRenderer), overriding the getTreeCellRendererComponent() method to apply different colors to the entry based on the 'value' parameter, and setting it on your tree. You can find easy examples of extending DefaultTreeCellRenderer on this site or many others, just by searching for it...
 
This is my favorite tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic