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

getActiveWindow returns null after closing native dialog

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P3 P3
    • None
    • 5.0
    • client-libs
    • generic
    • windows_xp

      It happens 80% of the time using Mozilla when the dialog is cancelled but less frequent in IE and appletviewer.

      Here is the code that demonstrates the problem:

      import java.awt.*;
      import java.awt.event.*;
      import java.applet.*;
      import java.awt.print.*;
      import javax.swing.*;

      public class AWTPrintTest extends JApplet implements Printable {
          private JButton jButton1 = new JButton();


          public AWTPrintTest() {
          }

          public void init() {
              try {
                  jbInit();
              }
              catch(Exception e) {
                  e.printStackTrace();
              }
          }

          private void jbInit() throws Exception {
              jButton1.setText("PRINT");
              jButton1.addActionListener(new java.awt.event.ActionListener() {
                  public void actionPerformed(ActionEvent e) {
                      jButton1_actionPerformed(e);
                  }
              });
            jButton1.setBounds(new Rectangle(165, 248, 80, 30));
              this.setSize(new Dimension(400,300));
            this.getContentPane().setLayout(null);
            this.getContentPane().setBackground(Color.pink);
              this.getContentPane().add(jButton1, BorderLayout.SOUTH);
          }

          public void start() {
          }

          public void stop() {
          }

          public void destroy() {
          }

          public String getAppletInfo() {
              return "Applet inf";
          }

          public String[][] getParameterInfo() {
              return null;
          }

         public void paint(Graphics g) {
            super.paint(g);
            g.setColor(Color.black);
            g.drawString("Hello World", 20, 100);
         }

         public int print(Graphics g, PageFormat pf, int page) throws PrinterException {
            return Printable.NO_SUCH_PAGE;
         }

          void jButton1_actionPerformed(ActionEvent e) {
            PrinterJob printJob = null;
            PageFormat pageFormat = null;
            boolean bPrintFlg = true;
         
            try{
               printJob = PrinterJob.getPrinterJob();

            }
            catch(SecurityException se){

               bPrintFlg = false;
            }

            if (bPrintFlg) {

      printJob.pageDialog(printJob.defaultPage());
      System.out.println("AWTPrintTest: getActiveWindow after pageDialog = "+KeyboardFocusManager.
      getCurrentKeyboardFocusManager().getActiveWindow());
               
              printJob.printDialog();
      System.out.println("AWTPrintTest: getActiveWindow after printDialog = "+KeyboardFocusManager.
      getCurrentKeyboardFocusManager().getActiveWindow());
            }
          }
      }
      =============

            art Artem Ananiev (Inactive)
            jgodinez Jennifer Godinez (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: