JDK-7002612 : REGRESSION:JApplets, JDialogs and JFrame are empty
  • Type: Bug
  • Component: deploy
  • Sub-Component: plugin
  • Affected Version: 7
  • Priority: P2
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2010-11-24
  • Updated: 2011-01-27
  • Resolved: 2011-01-27
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 7
7Resolved
Related Reports
Duplicate :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
With Java 7 we have the problem that many JApplets , JDialogs and JFrams are empty. 
There is only a gray surface. After debugging and find the cause of the problem. 
Adding a component to the content pane does not invalidate the JApplet, JDialog or JFrame. 

In Java 6 and before the parent object was invalidate in this case.

 

Workaround:

Calling manual invalidate() after any change on the root objects.


Sample Code:

import java.awt.BorderLayout;
import java.awt.Container; 
import javax.swing.*;

public class TestApplet extends JApplet {
    @Override
    public void init() {
        validate();      

        JSplitPane split = new JSplitPane();
        split.setLeftComponent( new JLabel( "left" ) );
        split.setRightComponent( new JLabel( "Right" ) );
        getContentPane().add( split, BorderLayout.CENTER ); 

        Container container = split;
        while( container != null ) {
            System.err.println( container.getClass().getName() + " " + (container.isValid() ? "" : "invalid") );
            container = container.getParent();
        } 

        //workaround: call manual invalidate()
        //invalidate();
    }
}
 

Output from Java 6:
===============
javax.swing.JSplitPane invalid
javax.swing.JPanel invalid
javax.swing.JLayeredPane invalid
javax.swing.JRootPane invalid
TestApplet invalid
sun.applet.AppletViewerPanel invalid
sun.applet.AppletViewer invalid


Output from Java 7:
===================
javax.swing.JSplitPane invalid
javax.swing.JPanel invalid
javax.swing.JLayeredPane invalid
javax.swing.JRootPane invalid
TestApplet
sun.applet.AppletViewerPanel
sun.applet.AppletViewer

Comments
EVALUATION CR 7002856 will provide access to the validateUnconditionally() method. As soon as it's fixed, this method should be called sometime after applet's init() is called. I'm re-dispatching this CR to plugin team since the call must be performed in the plugin code.
25-11-2010

EVALUATION Actually, any applet is always places in an embedded frame (a descendant of sun.awt.EmbeddedFrame). The frame's show() method gets indeed called, but usually it's done in the constructor (e.g. see WEmbeddedFrame), which happens long before the applet's init() method is invoked. This is done for historical reasons and cannot be changed due to backward compatibility issues. Plugin does indeed revalidates its component hierarchy after the init() is called because it expects that performing any layout-related operations invalidates the whole component hierarchy up to its root. However, after 6852592 is fixed invalidation stops when it encounters a validate root. For JApplet this is the JApplet's RootPane. Hence, the applet itself stays valid, and as such the plugin's subsequent validation bypasses it. To fix this issue we need to make plugin perform *unconditional* (!) validation right after calling init() (or wherever it's done presently actually). AWT has the needed functionality, however it may be inaccessible yet.
25-11-2010

EVALUATION Must be a regression of 6852592. However, with that fix the Window's show() method should validate the whole component hierarchy unconditionally. So it's unclear why the issue is happening.
25-11-2010

EVALUATION I reproduced this problem with the latest JDK 7 bits. This is a regression from recent JDK 7 fixes on AWT side, applets must be unconditionally validated before it is started.
25-11-2010