JDK-6662532 : Descendants of JWindow/JFrame/JDialog can not be made translucent
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 6u10
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2008-02-13
  • 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
Related Reports
Relates :  
Unable to enable the per-pixel alpha effect for descendants of JWindow, JFrame, or JDialog. However, the effect works fine for objects of these classes.

SUGGESTED FIX --- old/src/share/classes/java/awt/Window.java 2008-02-15 13:21:45.000000000 +0300 +++ new/src/share/classes/java/awt/Window.java 2008-02-15 13:21:45.000000000 +0300 @@ -3159,6 +3159,16 @@ return visible; } + private static boolean doesClassImplement(Class cls, String interfaceName) { + if (cls == null) return false; + + for (Class c : cls.getInterfaces()) { + if (c.getName().equals(interfaceName)) { + return true; + } + } + return doesClassImplement(cls.getSuperclass(), interfaceName); + } /** * Checks that the given object implements the given interface. @@ -3171,13 +3181,7 @@ if (obj == null) return false; if (interfaceName == null) return false; - Class cls = obj.getClass(); - for (Class c : cls.getInterfaces()) { - if (c.getName().equals(interfaceName)) { - return true; - } - } - return false; + return doesClassImplement(obj.getClass(), interfaceName); } private static final Color TRANSPARENT_BACKGROUND_COLOR =

WORK AROUND The user may declare that his/her top-level class that is descendant of the JWindow, JFrame, or JDialog class, implements the RootPaneContainer interface: class MyFrame extends JFrame implements RootPaneContainer { ... } The user doesn't need to implement any additional methods as the JWindow, JFrame, and JDialog already implement this interface.

EVALUATION The new feature introduced with CR 6633275 enables translucency effects for top-level windows (all the descendants of the java.awt.Window class). If the user uses the top-level classes of the Swing framework (JWindow, JFrame, or JDialog), some additional actions should be performed to make these windows translucent. All the actions are handled automatically by the code of the feature. To identify the necessity of the additional actions, the code verifies whether the top-level window object implements the javax.swing.RootPaneContainer interface (JWindow, JFrame, and JDialog do implement it). To avoid loading of the Swing classes for pure-AWT applications, the code uses a newly introduced (private) method boolean Window.doesImplement(Object cls, String interfaceName). This method uses the Class.getInterfaces() method to retrieve the interfaces implemented by the class of the object cls. However, the mentioned getInterfaces() method returns only the interfaces that have been explicitly declared with the 'implements' clause whilde declaring the class of the object cls. Which means, that objects of the JWindow, JFrame, and JDialog are correctly identified as needing some additional actions, but their descendants cannot be identified this way. We need to rearchitect the doesImpelment() method so that it traverses the whole hierarchy of the classes and checks whether any of the ancestors of the class of the cls object implement the given interface.