JDK-6640341 : Nimbus L&F: DefaultTreeCellRenderer issues with JTrees
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 6u10
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2007-12-11
  • Updated: 2011-02-16
  • Resolved: 2008-02-04
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
JRE6u10b08

ADDITIONAL OS VERSION INFORMATION :
Windows XP SP2

A DESCRIPTION OF THE PROBLEM :
When using a DefaultTreeCellRenderer with a JTree under Nimbus, the background of the TreeCell doesn't match the tree. Consider using a UI Delegate approach like the one used for JTables. We use a lot of DefaultTreeCellRenderers with our trees, pretty much simply to provide more control over the icons.

(From reading the forums, it seems clear that the issue is that DefaultTreeCellRenderer doesn't delegate most of its painting stuff to the LAF, resulting in a mismatched appearance. I worked around it by pulling the appropriate colors from the LAF and manually setting the colors in the cell renderer, but this still doesn't look great because the cell renderer isn't really painting using the LAF painter; the JTree selection is rendered with a sort of gradient along the edges but the cell renderer winds up being a flat opaque box.)

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Use Nimbus.
2. Create a JTree with anything in it.
3. Set the tree cell renderer to an instance of DefaultTreeCellRenderer (or a derived class.)
4. Enjoy.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I was hoping I wouldn't have to do the following:

(1) Extract the UIDefaults to a CSV file, import into Excel, find the Nimbus keys for TreeCellRenderer colors, manually set those colors in my cell renderer based on selection and focus status, plus
(2) Add a focus listener to my trees to ensure that they repaint whenever focus is lost or gained, because otherwise the selection within the tree doesn't get repainted as fast as the tree cell, and you wind up with mismatched colors for your tree selection. (This might be a Nimbus/JTree issue in general, not just with DefaultTreeCellRenderer.)
ACTUAL -
The JTree failed to look mindblowingly awesome.

REPRODUCIBILITY :
This bug can be reproduced always.

CUSTOMER SUBMITTED WORKAROUND :
Do the following:

(1) Extract the UIDefaults to a CSV file, import into Excel, find the Nimbus keys for TreeCellRenderer colors, manually set those colors in your cell renderers based on selection and focus status.

(2) Add a focus listener to trees to ensure that they repaint whenever focus is lost, because otherwise the selection within the tree doesn't get repainted as fast as the tree cell. (This might be a Nimbus/JTree issue in general, not just with DefaultTreeCellRenderer.)