Primm
Primm

Reputation: 1387

Java - Print document with dialog?

How do I open up a print dialog box where you select your printer, page details, etc to print A SPECIFIED DOCUMENT OR JTEXTPANE?

Please help!

note: getDesktop().print gives me an error about printer setup, how to open the native print dialog?

Upvotes: 3

Views: 15905

Answers (2)

tenorsax
tenorsax

Reputation: 21223

Check out Lesson: Printing in Java tutorials, Using Print Setup Dialogs in particular. PrinterJob.printDialog() should do the trick.

Upvotes: 5

Konrad Reiche
Konrad Reiche

Reputation: 29493

An application displays a print dialog when the user presses a button related to the print command, or chooses an item from the print menu. To display this dialog, call the printDialog method of the PrinterJob class:

PrinterJob pj = PrinterJob.getPrinterJob();
//...
    if (pj.printDialog()) {
        try {pj.print();}
        catch (PrinterException exc) {
            System.out.println(exc);
         }
     }   
//...  

Reference:

Upvotes: 3

Related Questions