Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6602293

Wrong focus traversal between multiple applets after printing

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      x86
    • OS:
      windows_xp

      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>

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              art Artem Ananiev
              Reporter:
              elarsen Erik Larsen (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: