JDK-4628179 : REGRESSION: AWT applet background doesn't refresh correctly
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.4.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2002-01-24
  • Updated: 2002-10-24
  • Resolved: 2002-10-24
Related Reports
Duplicate :  
Description

Name: jk109818			Date: 01/24/2002


FULL PRODUCT VERSION :
java version "1.4.0-beta3"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta3-b84)
Java HotSpot(TM) Client VM (build 1.4.0-beta3-b84, mixed mode)


FULL OPERATING SYSTEM VERSION :
Microsoft Windows 2000 [Version 5.00.2195]



A DESCRIPTION OF THE PROBLEM :
If you create an applet using GridBagLayout and
GridBagConstraints, the background of the applet doesn't
get refreshed correctly.  This bug only effects the
background.  Any other components do get updated
correctly.  I didn't try other layouts, but I suspect the
bug also effects them.

I tried the following applet in IE 5.5, Netscape 4.78,
Netscape 6.X and Mozilla 0.97.  The same problems occur in
all of them:

1) When you minimize the browser and restore it, the applet
background displays what was behind that part of the
browser window when you minimized it.

2) When, with the applet displayed inside the browser, you
move another window around above the applet, bits and
pieces of that window get displayed in the applet
background.

Here's the source code of an applet that will always
reproduce the problem:

package refreshbug;

import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
import java.util.*;
import java.security.*;

public class RefreshBug extends Applet
{
    protected Button button;

    public void init() {
        button = new Button("Button");
        GridBagLayout gridBag =
            new GridBagLayout();
        setLayout(gridBag);
        GridBagConstraints c =
            new GridBagConstraints();
        c.gridx = 0;
        c.gridy = 0;
        c.gridwidth = GridBagConstraints.CENTER;
        c.insets = new Insets(10,20,20,10);
        gridBag.setConstraints(button,c);
        add(button);
    }

}



This bug can be reproduced always.

CUSTOMER WORKAROUND :
Here's the same applet with source added to work around the
background refresh bug.  You need to add a paint method
which completely clears the rectangle to be updated.
Oddly, you also need to fire a MOUSE_MOVED event to force
the background to actually be cleared.  And in order for
the event to be received (and for this solution to work)
you need to add an AWT event listener for mouse motion
events.  But that's only possible in a signed applet.

package refreshbug;

import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
import java.util.*;
import java.security.*;

public class RefreshBug extends Applet
{
    protected Button button;

    public void init() {
        button = new Button("Button");
        GridBagLayout gridBag =
            new GridBagLayout();
        setLayout(gridBag);
        GridBagConstraints c =
            new GridBagConstraints();
        c.gridx = 0;
        c.gridy = 0;
        c.gridwidth = GridBagConstraints.CENTER;
        c.insets = new Insets(10,20,20,10);
        gridBag.setConstraints(button,c);
        add(button);
        final AWTEventListener cat =
            new AWTEventListener()
            {
                public void eventDispatched
                    (AWTEvent e)
                {
                }
            };
        AccessController.doPrivileged
            (new PrivilegedAction()
        {
            public Object run() {
                getToolkit().addAWTEventListener
                    (cat,AWTEvent.
                    MOUSE_MOTION_EVENT_MASK);
                return null;
            }
        });
    }

    public void paint(Graphics g) {
        Rectangle clip = g.getClipBounds();
        g.clearRect(clip.x,clip.y,clip.width,
            clip.height);
        MouseEvent scamper = new MouseEvent(this,
            MouseEvent.MOUSE_MOVED,
            new Date().getTime(),0,
            (clip.width-clip.x)/2,
            (clip.height-clip.y)/2,0,
            false);
        dispatchEvent(scamper);
    }

}

Release Regression From : 1.3.1
The above release value was the last known release where this 
bug was knwon to work. Since then there has been a regression.

(Review ID: 138482) 
======================================================================

Comments
EVALUATION I am not able to reproduce it with Merlin FCS in Java Plug-in in any browser. Reassign to AWT team to see if there is any insight. ###@###.### 2002-02-14 This is reproducible in Appletviewer with 1.4.0 and 1.4.1 ###@###.### 2002-10-21 It turns out that is is because of Gdi batching. Dmitri had a similar bug (4374079) which had the same symptom. Moving the mouse caused the window to be updated. Chet pointer me to Dmitris build and I tried it. Dmitri had put in a GdiSetBatchLimit(1) to stop GDI batching. This solved the problem. So this bug is fixed by the same fix. I will dup this bug to 4374079. 4374079 is committed to be fixed in Mantis. ###@###.### 2002-10-24
24-10-2002