Duplicate :
|
|
Relates :
|
|
Relates :
|
|
Relates :
|
|
Relates :
|
|
Relates :
|
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
|