United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: 6662532 Descendants of JWindow/JFrame/JDialog can not be made translucent
6662532 : Descendants of JWindow/JFrame/JDialog can not be made translucent

Details
Type:
Bug
Submit Date:
2008-02-13
Status:
Resolved
Updated Date:
2011-01-19
Project Name:
JDK
Resolved Date:
2008-03-04
Component:
client-libs
OS:
generic
Sub-Component:
java.awt
CPU:
generic
Priority:
P2
Resolution:
Fixed
Affected Versions:
6u10
Fixed Versions:
6u10

Related Reports
Relates:

Sub Tasks

Description
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.

                                    

Comments
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 =
                                     
2008-02-15
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.
                                     
2008-02-13
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.
                                     
2008-02-13



Hardware and Software, Engineered to Work Together