JDK-4880234 : ServiceUI needs a printDialog method wtih a Component parameter
  • Type: Enhancement
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 1.4.1
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2003-06-18
  • Updated: 2016-03-22
Description

Name: rl43681			Date: 06/17/2003


A DESCRIPTION OF THE REQUEST :
The javax.print.ServiceUI.printDialog method requires x and y coordinates, forcing application writers to arbitrarily place a dialog whose size is unknown.  A second printDialog method is needed which takes a Component instead of x and y coordinates.  The printDialog method could use that Component to place the dialog it creates, much like JOptionPane does.

JUSTIFICATION :
The javax.print.ServiceUI.printDialog method takes, among other things, a GraphicsConfiguration and x and y coordinates as parameters.  However, in most cases, I want the print dialog to be displayed so that it is centered over the window whose controls were used to invoke the print dialog (that is, the window containing the "Print" button or menu item).  Since I have no way to determine the size of the dialog ServiceUI.printDialog will display, I cannot effectively center it.  In fact, I have no way to determine "good" (aesthetic) x and y values;  the best I can do is have my code act like a simple-minded window manager and add an arbitrary number (like 30) to the x and y of the "parent" window.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I would like to see a method in javax.print.ServiceUI with a signature like this:

public static PrintService printDialog(
    java.awt.Component parent,
    PrintService[] services,
    PrintService defaultService,
    DocFlavor flavor,
    PrintRequestAttributeSet attributes)
throws HeadlessException

The dialog it creates would then be placed using Window.setLocationRelativeTo (just like JOptionPane).  Notice also that there is no need for the GraphicsConfiguration parameter, since it can be obtained from the Component.

CUSTOMER SUBMITTED WORKAROUND :
Frame frame;

private void printData()
throws PrintException
{
    // Just guess at x and y by adding 30

    PrintService selectedService = ServiceUI.printDialog(
        this.frame.getGraphicsConfiguration(),
        this.frame.getX() + 30,
        this.frame.getY() + 30,
        PrintServiceLookup.lookupPrintServices(null, null),
        null,
        null,
        new HashPrintRequestAttributeSet());

    if (selectedService != null)
    {
        selectedService.createPrintJob().print(createDoc(), null);
    }
}
(Review ID: 186949) 
======================================================================