JDK-6661657 : shape doesn't work with nonOpaque in Vista
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 6u10
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_vista
  • CPU: x86
  • Submitted: 2008-02-11
  • Updated: 2011-01-19
  • Resolved: 2008-03-04
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.
6u10 b13Fixed 7Resolved
Related Reports
Relates :  
Java Version: 1.6.0_10-ea-b11
Platform: Windows-Vista

I have a test case which when you select shaped and nonOpaque box, the windows is not shaped in vista, but it works fine in windowsXPpro.
Please see attached test cases.

How to reproduce the problem:
1, compile the attached test cases;
2, run the test and select shaped and nonOpaque boxes both, you will see window comes up.
in winXP, you can see it is shaped, but in Vista, it is not.

SUGGESTED FIX --- old/src/windows/classes/sun/awt/windows/WWindowPeer.java 2008-02-18 17:03:04.000000000 +0300 +++ new/src/windows/classes/sun/awt/windows/WWindowPeer.java 2008-02-18 17:03:04.000000000 +0300 @@ -590,7 +590,9 @@ return; } - if (this.isOpaque != isOpaque && !Win32GraphicsEnvironment.isVistaOS()){ + boolean opaqueChanged = this.isOpaque != isOpaque; + + if (opaqueChanged && !Win32GraphicsEnvironment.isVistaOS()){ // non-Vista OS: only replace the surface data if the opacity // status changed (see WComponentPeer.isAccelCapable() for more) replaceSurfaceDataRecursively((Component)getTarget()); @@ -600,6 +602,13 @@ setOpaqueImpl(isOpaque); updateWindow(null); + + if (opaqueChanged) { + Shape shape = AWTAccessor.getWindowAccessor().getShape((Window)target); + if (shape != null) { + AWTAccessor.getWindowAccessor().setShape((Window)target, shape); + } + } } private native void updateWindowImpl(int[] data, int width, int height);

EVALUATION The effect is only observed if the user makes the frame non-opaque after setting the shape. If the user first makes her/his frame non-opaque, and only after that sets the shape, the frame behaves as expected. Seems to be the native system issue (as per the previous evaluation, the system does respect the shape in terms of the mouse clicks).

EVALUATION The results of some experiments: 1. This issue is not reproducible when running over rdesktop connection. 2. This issue is not reproducible when the setWindowShape() invokation happens in the componentResized() of the component listener (which should, probably, be considered the recommended practice). 3. When this problem is reproducible, Windows respects the shape in terms of mouse-clicks, meaning the user may click into the areas that should not be painted, and these clicks get correctly dispatched to other applications (under the translucent window). 4. After runnning java with -Dsun.java2d.trace=log for the first time, the bug disappeared.