JDK-7026051 : appletviewer cannot show swing components
  • Type: Bug
  • Component: tools
  • Sub-Component: appletviewer
  • Affected Version: 7
  • Priority: P4
  • Status: Closed
  • Resolution: Not an Issue
  • OS: generic
  • CPU: generic
  • Submitted: 2011-03-09
  • Updated: 2011-03-10
  • Resolved: 2011-03-10
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
Relates :  
Relates :  
Relates :  
Description
SYNOPSIS
--------
appletviewer cannot show swing components

OPERATING SYSTEMS
-----------------
Redhat Enterprise Linux 6
Windows XP

FULL JDK VERSION
----------------
java version "1.7.0-ea"
Java(TM) SE Runtime Environment (build 1.7.0-ea-b132)
Java HotSpot(TM) Client VM (build 21.0-b03, mixed mode)

DESCRIPTION
-----------
This is not reproducible when the applet is run in the browser.
This is reproducible using appletviewer.

This looks very similar to CR 7002612, which was closed as a duplicate of CR 6986229. However, issue can reproduce this issue on 7-b132 despite the fix for 6986229 being delivered in b123.

Appletviewer cannot show its inner components just after starting. When I resize the appletviewer's window, I can see the inner components correctly. A similar AWT sample didn't have the problem.

Adding invalidate() at the end of the init() method in the testcase works around issue.


--- swing.html ---
<html>
<body>
<applet code="swing.class" height=300 width=300>
</applet>
</body>
</html>
------------------

--- swing.java ---
import java.awt.*;
import javax.swing.*;
import java.applet.Applet;

public class swing extends JApplet {
   public void init(){
        Container c = this.getContentPane();
        c.setLayout(new BorderLayout());
        JScrollPane scrollPane = new JScrollPane();
        scrollPane.getViewport().add(new JTextArea());
        c.add("Center",scrollPane);
        c.add("South",new JTextField());
	// workaround	
	// invalidate () ; 
   }
}
------------------

REPRODUCTION INSTRUCTIONS
-------------------------
Compile the sample code and load html by appletviewer. Note that the appletviewer doesn't show inner components. It shows grey background.

WORKAROUND
----------
See testcase (add invalidate()).

Comments
EVALUATION According to java doc: "If a component has been added to a container that has been displayed, validate must be called on that container to display the new component. If multiple components are being added, you can improve efficiency by calling validate only once, after all the components have been added. " Technically, appletviewer could revalidate its components before showing but current behaviour does not contradict java doc specification. c.validate(); // - fixes the problem
10-03-2011