JDK-6206442 : REGRESSION: JFrame goes to back after toFront() is called when Applet starts
  • Type: Bug
  • Component: deploy
  • Sub-Component: plugin
  • Affected Version: 5.0
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2004-12-09
  • Updated: 2011-02-16
  • Resolved: 2006-12-07
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.
Other
5.0u11 b02Fixed
Related Reports
Relates :  
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.5.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
Upon launching an applet, if the applet tries to display a JFrame in front of it's web browser window using the .toFront() method, the JFrame appears momentarily then disappears behind the browser window.

The same behaviour is experienced on
IE version: 6.0.2900.2180.xpsp_sp2_rtm.040803-2158
Firefox version 1.0

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Save the two source code snippets as ToFrontTest.java and ToFrontTest.html.
Compile ToFrontTest.java and launch ToFrontTest.html with the web browser window maximised.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The frontFrame should appear and stay in front of the applet/web browser .
ACTUAL -
The frontFrame appears momentarily then disappears behind the applet/web browser.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.*;
import java.applet.*;
import javax.swing.*;
 
public class ToFrontTest extends Applet
{
    public ToFrontTest()
    {
    }
    public void init()
    {
        JFrame frontFrame = new JFrame("toFront() Test Frame");
        frontFrame.getContentPane().setLayout(new BorderLayout());
        frontFrame.getContentPane().add(new JLabel("Am I in front?"),BorderLayout.CENTER);
        frontFrame.setSize(300, 300);
        frontFrame.setVisible(true);
        frontFrame.toFront();
    }
}

------------------------------

<html>
<head>
<title>ToFront() HTML Test Page</title>
</head>
<body>
  ToFrontTest will appear below in a Java enabled browser.<br>
<applet
  codebase = "."
  code     = "ToFrontTest.class"
  name     = "ToFrontTest"
  width    = "400"
  height   = "300"
  hspace   = "0"
  vspace   = "0"
  align    = "middle"
>
</applet>
</body>
</html>
---------- END SOURCE ----------

Release Regression From : 1.4.2
The above release value was the last known release where this 
bug was known to work. Since then there has been a regression.
###@###.### 2004-12-09 15:23:35 GMT

Comments
EVALUATION Below comments from Calvin Cheung: It's not a javac issue. The reason is that there's a hasInitialFocus method in sun.plugin.AppletViewer. In that method, it checks for the applet's class version, if it's of version 1.1 or 1.2, the method returns false. That method is called in sun.awt.AppletPanel and will set focus to the applet it the method returns true. I guess this is the expected behavior. To override this behavior, you can set the "initial_focus" html parameter to "false" and it'll work with the version of class file newer than 1.2.
12-12-2006

EVALUATION An interesting behaviour has been observed w.r.t the testcase: - The testcase when compiled with 1.4.2 and run with the fix, it works fine - The testcase when compiled with 1.5.0 and run with the fix, it fails ie. the frame goes behind the browser. I am following up with the javac team to see if it could be a javac issue.
11-12-2006

EVALUATION On further investigation, I figured out that the regression has been caused by the fix for 6334864 that went into 5.0u8 b01. The fix for the current bug is different from 4984794 and hence reopened the bug. It looks like a timing issue here where f.synthesizeWindowActivation(true); resets the focus back to the applet and hence the frame (that's supposed to be on top) goes behind the browser. As far as I see the above call is not required in statusChanged method. We make this call anyway on Embeddedframe's activate call (in CJavaFrame.cpp). Please correct me if I am wrong here.
17-10-2006

EVALUATION Known problem. Closing as duplicate of AWT focus bug. ###@###.### ###@###.### 2004-12-09 23:01:49 GMT
09-12-2004