JDK-6708509 : print dialog is not displayed when default paper is custom
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: generic
  • Submitted: 2008-05-29
  • Updated: 2011-03-08
  • Resolved: 2011-03-08
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6 JDK 7
6u10Fixed 7 b33Fixed
Description
While testing the following test program with Dymo Label Printer 330 Turbo, the program just exits without any print dialog or error message.  Other printer drivers like laser printer drivers shows the dialog.  It is not always reproducible.

import java.util.Vector;
import java.awt.print.*;
import java.awt.*;
import javax.swing.JPanel;

public class DymoLabelPrinting{

    public static void main(String args[])
    {
        Vector vLabels = new Vector();
        vLabels.add("Mr.TIGERWOODS");
        vLabels.add("H NO 2-7, AMEERPET");
        vLabels.add("HYDERABAD");
        vLabels.add("ANDHRA PRADESH,INDIA");

        PrintLabels printLabels = new PrintLabels(vLabels);

        printLabels.prepareLabels();

        Thread labelPrintingThread=new Thread(printLabels);

        labelPrintingThread.start();
    }
}

//-------------------------------------------

class PrintLabels implements Runnable
{


    Vector records;
    String strOrientation;

    PageFormat pageFormat;
    PrinterJob printJob;

    Page page ;

    public PrintLabels(Vector vector)
    {
        pageFormat             = null;
        printJob             = null;
        strOrientation             = "Landscape";
        records             = vector;
    }

    public void run()
    {
        print();
    }

    public void prepareLabels()
    {
        page = new Page();
        page.addLabel(records);
    }


    public void print()
    {
        printJob = PrinterJob.getPrinterJob();

        try
        {
            Paper paper = new Paper();
            paper.setSize(165, 288);
            paper.setImageableArea(7, 0, 165, 288);

            pageFormat = printJob.defaultPage();
            pageFormat.setPaper(paper);

            if(strOrientation.equals("Portrait"))
                pageFormat.setOrientation(pageFormat.PORTRAIT);
            else
                pageFormat.setOrientation(pageFormat.LANDSCAPE);


            printJob.setPrintable(page, pageFormat);

            if(printJob.printDialog()==false)
                return;

            printJob.print();

        }catch(PrinterException e){
            e.printStackTrace();
        }

    }

}
------------------------------------------------------

Comments
EVALUATION JDK thinks there is no default printer so it did not try to display the dialog this is because one of the conditions for finding out if there's a default printer is if DM_PAPERSIZE of DEVMODE is initialized. For this particular driver where all paper sizes are non-standard Windows, driver sometimes only initializes DM_PAPERWIDTH and DM_PAPER_LENGTH but not DM_PAPERSIZE.
29-05-2008