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

Cross-platform PrinterJob.printDialog gets hidden by main application window

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.4.2_04
    • 1.4.1, 1.4.2
    • client-libs
    • 2d
    • 04
    • x86
    • windows_2000
    • Verified



        Name: jk109818 Date: 11/07/2002


        FULL PRODUCT VERSION :
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0_02-b02)
        Java HotSpot(TM) Client VM (build 1.4.0_02-b02, mixed mode)

        AND

        java version "1.4.1_01"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-b01)
        Java HotSpot(TM) Client VM (build 1.4.1_01-b01, mixed mode)

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

        A DESCRIPTION OF THE PROBLEM :
        The PrinterJob.printDialog class does not provide a method
        for constructing a cross-platform Print dialog that accepts
        an "owner" Dialog or Frame, in contrast to the constructors
        provided by the Swing JDialog class which do allow the
        specification of an owner. The result is that the Print
        dialog can be hidden inadvertently behind its main
        application window and users think they've "lost" the
        dialog. Since the Print dialog is modal, it isn't even
        possible to select the main application window for the
        purpose of moving it aside so as to expose the dialog
        behind it.



        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        1. Compile and run the attached program. The main
        application window will appear.

        2. Click on the Print button. The cross-platform print
        dialog will appear, centered over the application window.

        2. Open, or click on, another application window on the
        desktop (for example, Internet Explorer or Windows
        Explorer).

        3. From the Windows taskbar, click on the coffee-cup icon
        for the sample application started in step 1.



        EXPECTED VERSUS ACTUAL BEHAVIOR :
        I would expect the Print dialog to appear on top of the
        main application frame. Instead the main application
        window appears on top of, and hides, the Print dialog, and
        since the Print dialog is modal, it isn't even possible to
        select the main application window for the purpose of
        moving it aside so as to expose the dialog.

        I would like, instead, for the Print dialog to appear on
        top of the main application window when the application
        window is brought to the front. This is the behavior that
        occurs for Swing JDialogs that are instantiated using the
        constructors that take an "owner" Dialog or Frame.


        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        import java.awt.BorderLayout;
        import java.awt.Container;
        import java.awt.event.ActionEvent;
        import java.awt.event.ActionListener;
        import java.awt.print.Printable;
        import java.awt.print.PrinterException;
        import java.awt.print.PrinterJob;
        import javax.print.attribute.HashPrintRequestAttributeSet;
        import javax.print.attribute.PrintRequestAttributeSet;
        import javax.swing.JButton;
        import javax.swing.JFrame;
        import javax.swing.JLabel;
        import javax.swing.SwingConstants;

        public class PrinterJobDialogBugDemo extends JFrame implements Printable {

          public static void main(String[] args) {
            new PrinterJobDialogBugDemo();
          }

          private PrinterJobDialogBugDemo() {
            super("Printer Job Dialog Bug Demo");

            setDefaultCloseOperation(EXIT_ON_CLOSE);
            setSize(700,700);
            
            JButton btnPrint = new JButton("Print...");
            btnPrint.addActionListener(new ActionListener()
              {
                public void actionPerformed(ActionEvent ae) {
                  showPrintDialog();
                }
              });

            Container contentPane = getContentPane();
            contentPane.add(
              new JLabel("<html>This is the main Application Window. " +
                         "To demonstrate the problem:" +
                         "<ol>" +
                         "<li>Click the Print button at the bottom of this window. " +
                         "The Print dialog will appear." +
                         "<li>Select another application window." +
                         "<li>On the Windows taskbar, click the coffee-cup icon for " +
                         "this demo application. This brings this window to the " +
                         "front but the Print dialog remains hidden. " +
                         "Since this window " +
                         "is no longer selectable, it can't be moved aside to expose " +
                         "the Print dialog that is now behind it." +
                         "</ol>",
                         SwingConstants.CENTER),
              BorderLayout.NORTH);
            contentPane.add(btnPrint, BorderLayout.SOUTH);
            setVisible(true);
          }

          private void showPrintDialog() {
            PrinterJob printJob = PrinterJob.getPrinterJob();
            printJob.setPrintable(this);
            PrintRequestAttributeSet printRequestAttrSet =
              new HashPrintRequestAttributeSet();
            printJob.printDialog(printRequestAttrSet);
          }

          public int print(java.awt.Graphics g, java.awt.print.PageFormat pageFormat,
        int pageIndex) {
            if (pageIndex == 0) {
              return(PAGE_EXISTS);
            } else {
              return(NO_SUCH_PAGE);
            }
          }
        }

        ---------- END SOURCE ----------
        (Review ID: 166556)
        ======================================================================

              jgodinez Jennifer Godinez (Inactive)
              jkimsunw Jeffrey Kim (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: