JDK-4916664 : ServiceUI.printDialog gets hidden by main application window
  • Type: Enhancement
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 1.4.2
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2003-09-03
  • Updated: 2003-09-03
  • Resolved: 2003-09-03
Related Reports
Duplicate :  
Description

Name: rmT116609			Date: 09/03/2003


FULL PRODUCT VERSION :
java version "1.4.2_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_01-b06)
Java HotSpot(TM) Client VM (build 1.4.2_01-b06, mixed mode)

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

A DESCRIPTION OF THE PROBLEM :
The javax.print.ServiceUI.printDialog class does not
provide a constructor 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 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 often.

---------- BEGIN SOURCE ----------
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.print.DocFlavor;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.ServiceUI;
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 PrintDialogBugDemo extends JFrame {

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

  private PrintDialogBugDemo() {
    super("Print 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() {
    DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;

    PrintService printServices[] =
      PrintServiceLookup.lookupPrintServices(flavor, null);

    PrintService printService = PrintServiceLookup.lookupDefaultPrintService();
    PrintRequestAttributeSet printRequestAttrSet =
      new HashPrintRequestAttributeSet();

    PrintService newPrintService =
      ServiceUI.printDialog(null, 200, 200, printServices, printService,
                            flavor, printRequestAttrSet);
  }
}

---------- END SOURCE ----------

CUSTOMER WORKAROUND :
Wrote my own wrapper printDialog method, which instantiates
sun.print.ServiceDialog directly, creates a new JDialog
with an owner, and moves the content pane of the
sun.print.ServiceDialog into my own JDialog.  Added window
listeners to both dialogs to listen to each other's window
close events, so that each window disposes itself when the
other window is closed.  Obviously not a good solution
because it relies directly on the undocumented sun.print
package.
(Incident Review ID: 166515) 
======================================================================