Example usage for java.awt.print PrinterException toString

List of usage examples for java.awt.print PrinterException toString

Introduction

In this page you can find the example usage for java.awt.print PrinterException toString.

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:JuliaSet2.java

public void print() {
    // Java 1.1 used java.awt.PrintJob.
    // In Java 1.2 we use java.awt.print.PrinterJob
    PrinterJob job = PrinterJob.getPrinterJob();

    // Alter the default page settings to request landscape mode
    PageFormat page = job.defaultPage();
    page.setOrientation(PageFormat.LANDSCAPE); // landscape by default

    // Tell the PrinterJob what Printable object we want to print.
    // PrintableComponent is defined as an inner class below
    String title = "Julia set for c={" + cx + "," + cy + "}";
    Printable printable = new PrintableComponent(this, title);
    job.setPrintable(printable, page);/*from   w w w .  java  2s  .  c o m*/

    // Call the printDialog() method to give the user a chance to alter
    // the printing attributes or to cancel the printing request.
    if (job.printDialog()) {
        // If we get here, then the user did not cancel the print job
        // So start printing, displaying a dialog for errors.
        try {
            job.print();
        } catch (PrinterException e) {
            JOptionPane.showMessageDialog(this, e.toString(), "PrinterException", JOptionPane.ERROR_MESSAGE);
        }
    }
}

From source file:lu.fisch.unimozer.Diagram.java

public void printDiagram() {
    // print preview takes a lot of memory (don't know why)
    // so it is a good idea to sugest to the JVM to clean up the heap
    System.gc();//from  ww w.ja v  a  2s  .c om
    printOptions = PrintOptions.showModal(frame, "Print options");
    if (printOptions.OK == true) {
        this.deselectAll();
        this.cleanAll();
        this.repaint();

        if (printOptions.getJob() == PrintOptions.JOB_PREVIEW) {
            PrintPreview pp = new PrintPreview(frame, this);
            pp.setLocation(Math.round((frame.getWidth() - pp.getWidth()) / 2 + frame.getLocation().x),
                    (frame.getHeight() - pp.getHeight()) / 2 + frame.getLocation().y);
            pp.setVisible(true);
        } else {
            try {
                // Use default printer, no dialog
                PrinterJob prnJob = PrinterJob.getPrinterJob();

                // get the default page format
                PageFormat pf0 = prnJob.defaultPage();
                // clone it
                PageFormat pf1 = (PageFormat) pf0.clone();
                Paper p = pf0.getPaper();
                // set to zero margin
                p.setImageableArea(0, 0, pf0.getWidth(), pf0.getHeight());
                pf1.setPaper(p);
                // let the printer validate it
                PageFormat pf2 = prnJob.validatePage(pf1);
                //prnJob.pageDialog(prnJob.defaultPage());

                prnJob.setPrintable(this, pf2);
                if (prnJob.printDialog()) {
                    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                    prnJob.print();
                    setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
                }
            } catch (PrinterException ex) {
                ex.printStackTrace();
                System.err.println("Printing error: " + ex.toString());
            }
        }
    }
    System.gc();
}

From source file:org.jab.docsearch.DocSearch.java

private void doPrint() {
    PrinterJob pj = PrinterJob.getPrinterJob();
    pj.setJobName("docSearcher");
    pj.setPageable(vista);//from   w w w .j  a  v a 2 s.  com
    try {
        if (pj.printDialog()) {
            pj.print();
        }
    } catch (PrinterException pe) {
        logger.fatal("doPrint() failed with PrinterException", pe);
        showMessage(dsErrPrint, pe.toString());
    }
}