JDK-5027272 : JTree.getBackground() returns a different color than it is painted with
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 5.0
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86
  • Submitted: 2004-04-06
  • Updated: 2004-04-09
  • Resolved: 2004-04-09
Related Reports
Duplicate :  
Description
Found while diagnosing tree painting problems on GTK look and feel in NetBeans

At first I thought that the problem is actually not that our cell
renderers are ignoring setBackground(), but that they aren't.  They
are set to the tree's background value which is a. set incorrectly,
and b. ignored when painting the tree.

The tree's background is set correctly when instantiated.  Then, when
it is added to the main window, it's background is set to 204,204,204,
the default component background.  Except that 204,204,204 is not
actually what it is painted with (except for our renderers).

Probably the tree should not update its state when added to a parent,
or at least not its background color.

Initial stack trace setting the color correctly:
Returning javax.swing.plaf.ColorUIResource[r=255,g=255,b=255] for Tree, 1, TextBackground
setBackground: javax.swing.plaf.ColorUIResource[r=255,g=255,b=255] on 17095030
  javax.swing.plaf.synth.SynthStyle.installDefaults(SynthStyle.java:831)
  javax.swing.plaf.synth.SynthStyle.installDefaults(SynthStyle.java:810)
  javax.swing.plaf.synth.SynthLookAndFeel.updateStyle(SynthLookAndFeel.java:234)
  javax.swing.plaf.synth.SynthTreeUI.updateStyle(SynthTreeUI.java:69)
  javax.swing.plaf.synth.SynthTreeUI.installDefaults(SynthTreeUI.java:62)
  javax.swing.plaf.basic.BasicTreeUI.installUI(BasicTreeUI.java:616)
  javax.swing.JComponent.setUI(JComponent.java:625)
  javax.swing.JTree.setUI(JTree.java:538)
  javax.swing.JTree.updateUI(JTree.java:554)

Second stack trace setting the color incorrectly, with logging of the
property change:
UPDATING STYLE FOR ancestorjava.beans.PropertyChangeEvent[source=org.openide.explorer.view.TreeView$ExplorerTree[,0,0,0x0,invalid,alignmentX=0.0,alignmentY=0.0,border=javax.swing.plaf.synth.SynthBorder@2fe032,flags=16777576,maximumSize=,minimumSize=,preferredSize=,editable=false,invokesStopCellEditing=false,largeModel=false,rootVisible=false,rowHeight=-1,scrollsOnExpand=false,showsRootHandles=true,toggleClickCount=0,visibleRowCount=20]]
setBackground: javax.swing.plaf.ColorUIResource[r=204,g=204,b=204] on 16715083
  javax.swing.plaf.synth.SynthStyle.installDefaults(SynthStyle.java:831)
  javax.swing.plaf.synth.SynthStyle.installDefaults(SynthStyle.java:810)
  javax.swing.plaf.synth.SynthLookAndFeel.updateStyle(SynthLookAndFeel.java:234)
  javax.swing.plaf.synth.SynthTreeUI.updateStyle(SynthTreeUI.java:69)
  javax.swing.plaf.synth.SynthTreeUI.propertyChange(SynthTreeUI.java:485)
  java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:305)
  java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:242)
  java.awt.Component.firePropertyChange(Component.java:7104)
  javax.swing.JComponent.addNotify(JComponent.java:4392)


Although the stack trace above shows the tree's background being set to a light grey color (which it returns as its background property for the rest of its life), it actually is painted as white.  Any renderer which tries to set its non-selected background color based on the background color of the tree will pick up this grey color - so the tree background will be white, but each cell in the tree will have a grey background.  This looks embarassing and strange.

Note that this is only one of several tree cell renderer painting problems on GTK look and feel; fixing this will fix one source of the painting problem; however, if using a subclass of DefaultTableCellRenderer, the color will still be gray for other reasons.

Comments
EVALUATION Name: omR10226 Date: 04/08/2004 Please look at evaluation of 5027285. ======================================================================
11-06-2004

WORK AROUND Do not use/support GTK look and feel
11-06-2004

SUGGESTED FIX Ensure that the background property of the JTree is the color its background will actually be painted with, after it is added to a container; or do not have it update its style when added to a container.
11-06-2004