JDK-6661319 : PIT: Setting background color on top levels do not work
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 6u10
  • Priority: P1
  • Status: Closed
  • Resolution: Fixed
  • OS: generic,windows_xp
  • CPU: generic,x86
  • Submitted: 2008-02-10
  • Updated: 2011-01-19
  • Resolved: 2008-02-14
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6
6u10 b12Fixed
Related Reports
Duplicate :  
Relates :  
Description
Calling setBackground on AWT top level windows doesn't set the background color on 6u10 b12 PIT build. This is observed on Linux and Solaris platforms, not seen on Windows.

Comments
SUGGESTED FIX --- old/src/share/classes/java/awt/Window.java 2008-02-11 14:10:35.000000000 +0300 +++ new/src/share/classes/java/awt/Window.java 2008-02-11 14:10:35.000000000 +0300 @@ -3178,8 +3178,11 @@ return false; } + private static final Color TRANSPARENT_BACKGROUND_COLOR = + new Color(0, 0, 0, 0); + private transient Color preserveBackgroundColor = null; + private void setLayersOpaque(boolean isOpaque) { - Color bg = isOpaque ? SystemColor.window : new Color(0, 0, 0, 0); // Shouldn't use instanceof to avoid loading Swing classes // if it's a pure AWT application. if (doesImplement(this, "javax.swing.RootPaneContainer")) { @@ -3198,7 +3201,21 @@ content.setDoubleBuffered(isOpaque); //XXX: the "white rect" workaround } } - setBackground(bg); + + Color bg = getBackground(); + boolean hasTransparentBg = TRANSPARENT_BACKGROUND_COLOR.equals(bg); + + if (isOpaque) { + if (hasTransparentBg) { + setBackground(preserveBackgroundColor == null ? + SystemColor.window : preserveBackgroundColor); + } + } else { + if (!hasTransparentBg) { + preserveBackgroundColor = bg; + } + setBackground(TRANSPARENT_BACKGROUND_COLOR); + } } /* The opacity level of the window
11-02-2008

EVALUATION In order for the translucent windows feature to work correctly (see 6633275), the background color of windows needs to be tuned up. Currently, if the window is marked as translucent, the background is explicitly set to the value (R, G, B, A) = (0, 0, 0, 0), where A means 'alpha'. If the window is opaque (i.e. 'usual', 'not translucent') its background gets set to the value SystemColor.window which is the default for all windows. This causes ignoring the background color set by the user before making the window visible. The solution is to verify whether some background color has been set by the user. If this is true, and the window is opaque, we should not update the background color.
11-02-2008

WORK AROUND The user may set the background after making his/her window visible. In this case the background gets set correctly.
11-02-2008