United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6708509 print dialog is not displayed when default paper is custom
JDK-6708509 : print dialog is not displayed when default paper is custom

Details
Type:
Bug
Submit Date:
2008-05-29
Status:
Closed
Updated Date:
2011-03-08
Project Name:
JDK
Resolved Date:
2011-03-08
Component:
client-libs
OS:
windows_xp
Sub-Component:
2d
CPU:
generic
Priority:
P4
Resolution:
Fixed
Affected Versions:
5.0
Fixed Versions:

Related Reports
Backport:

Sub Tasks

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.
                                     
2008-05-29



Hardware and Software, Engineered to Work Together