JDK-6602293 : Wrong focus traversal between multiple applets after printing
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 6u2
  • Priority: P3
  • Status: Closed
  • Resolution: Cannot Reproduce
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2007-09-07
  • Updated: 2011-01-19
  • Resolved: 2007-12-04
Related Reports
Relates :  
Relates :  
Description
OPERATING SYSTEM
Windows XP 

FULL JDK VERSION(S):
java version "1.6.0_02"
Java(TM) SE Runtime Environment (build 1.6.0_02-b06)
Java HotSpot(TM) Client VM (build 1.6.0_02-b06, mixed mode, sharing)

DESCRIPTION:
In the case of mutiple applet scenario using print dialog, the focus after post Print or Cancel operation goes to the wrong applet (to the another applet and Not to the one which brings up)

Steps to recreate:
1. Compile PrintApplet.java (refer testcase below) and get the .class
   file. i.e "javac PrintApplet.java"
2. Using a browser, invoke "printapplet.html"
3. We have two applets loaded by the HTML page.
4. From one applet, bring up the Print dialog
5. Click Ok to print or Cancel for cancelling 
6. The print dialog will disappear and the focus will be returned to
   the wrong applet i.e. to the "other" applet, NOT to the one from
   which we opened the Print dialog.



TEST-CASE:

This consists of two files. "PrintApplet.java" & "printapplet.html"

----------------
PrintApplet.java:
-----------------

import java.awt.*;
import javax.swing.*;
import java.io.*;
import java.net.*;
import java.awt.event.*;

import java.awt.print.Printable;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import java.awt.print.PageFormat;

public class PrintApplet extends JApplet implements ActionListener
{

  JFrame jf;
  JPanel jp;
  JButton jb;
  PrinterJob printJob = null;

  public PrintApplet()
  {
        jf = new JFrame("Print Applet...");
        jp = new JPanel(new GridBagLayout());

        jb = new JButton("Press Here to Start the Print Dialog");
        jb.setBackground(new Color(255,0,0));
        jb.addActionListener(this);

        //Add Components to this panel.
        GridBagConstraints c = new GridBagConstraints();
        c.gridwidth = GridBagConstraints.REMAINDER;

        c.fill = GridBagConstraints.HORIZONTAL;

        c.fill = GridBagConstraints.BOTH;
        c.weightx = 1.0;
        c.weighty = 1.0;

        jp.add(jb, c);

	    jf.getContentPane().add(jp);
        jf.pack();
        jf.show();
  }

  public void init()
  {  }

  public void actionPerformed(ActionEvent evt)
  {
     if (evt.getSource().equals(jb) )
     {
		try {
        // Open PrintDialog 
        printJob = PrinterJob.getPrinterJob();
	 	if (printJob.printDialog()) {
        try {
		  printJob.pageDialog(new PageFormat());
		  printJob.print();
        } catch (Exception exception) {
          JOptionPane.showMessageDialog(this, exception);
        } // end of catch
        } //end of if
	    } catch (Exception e) {}
    } // end of if (jb)

  } // end of actionPerformed
}


-----------------
printapplet.html:
-----------------
<HTML>
<HEAD>
<TITLE> Sample Print Applet </TITLE>
</HEAD> <BODY>
<APPLET CODE="PrintApplet.class" WIDTH=500 HEIGHT=50> </APPLET>
<APPLET CODE="PrintApplet.class" WIDTH=500 HEIGHT=50> </APPLET>
</BODY>
</HTML>

Comments
EVALUATION The problem is not related to Java Plugin and can be reproduced with just two AWT frames, but only up to JDK7-b13, while in JDK7-b21 the problem is gone away. I guess it was fixed by the changes for 6538510 or 6494032.
04-12-2007