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
On what platform are you running? (I have seen funky color behavior on some Unices.) Bill
posted 17 years ago
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.
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
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:
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...
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Ew. You guys are ugly with a capital UG. Here, maybe this tiny ad can help: