Example usage for java.awt.print PrinterJob print

List of usage examples for java.awt.print PrinterJob print

Introduction

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

Prototype

public abstract void print() throws PrinterException;

Source Link

Document

Prints a set of pages.

Usage

From source file:JavaWorldPrintExample1.java

/**
 * Constructor: Example1//from ww w  . ja  v  a2 s  . com
 * <p>
 *  
 */
public JavaWorldPrintExample1() {

    //--- Create a printerJob object
    PrinterJob printJob = PrinterJob.getPrinterJob();

    //--- Set the printable class to this one since we
    //--- are implementing the Printable interface
    printJob.setPrintable(this);

    //--- Show a print dialog to the user. If the user
    //--- click the print button, then print otherwise
    //--- cancel the print job
    if (printJob.printDialog()) {
        try {
            printJob.print();
        } catch (Exception PrintException) {
            PrintException.printStackTrace();
        }
    }

}

From source file:org.schreibubi.JCombinations.ui.GridChartPanel.java

/**
 * Print panel/*from www . ja v a 2 s  .c  o m*/
 * 
 * @param printJob
 */
public void printMe(PrinterJob printJob) {
    try {
        printJob.print();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:com.alvermont.terraj.planet.ui.TerrainFrame.java

private void printItemActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_printItemActionPerformed
{//GEN-HEADEREND:event_printItemActionPerformed

    final PrinterJob printJob = PrinterJob.getPrinterJob();
    final PageFormat pf = printJob.pageDialog(printJob.defaultPage());

    printJob.setPrintable(new ImagePrinter(image, pf), pf);

    if (printJob.printDialog()) {
        try {//  www  .ja v a2s  . c o m
            printJob.print();
        } catch (Exception e) {
            log.error("Error printing", e);

            JOptionPane.showMessageDialog(this,
                    "Error: " + e.getMessage() + "\nCheck log file for full details", "Error Printing",
                    JOptionPane.ERROR_MESSAGE);
        }
    }
}

From source file:org.fhaes.fhfilechecker.FrameViewHelp.java

public void btnPrint_actionPerformed(ActionEvent e) {
    // Get a PrinterJob
    PrinterJob job = PrinterJob.getPrinterJob();
    // Ask user for page format (e.g., portrait/landscape)
    PageFormat pf = job.pageDialog(job.defaultPage());
    // Specify the Printable is an instance of
    // PrintListingPainter; also provide given PageFormat
    job.setPrintable(new PrintListingPainter(out_file_name), pf);
    // Print 1 copy
    job.setCopies(1);/*from  w  w w  .j  av a 2  s  . c om*/
    // Put up the dialog box
    if (job.printDialog()) {
        // Print the job if the user didn't cancel printing
        try {
            job.print();
        } catch (Exception ex) {
            /* handle exception */}
    }
}

From source file:PrintCanvas3D.java

void print() {
    PrinterJob printJob = PrinterJob.getPrinterJob();
    PageFormat pageFormat = printJob.defaultPage();
    pageFormat.setOrientation(PageFormat.LANDSCAPE);
    pageFormat = printJob.validatePage(pageFormat);
    printJob.setPrintable(this, pageFormat);
    if (printJob.printDialog()) {
        try {// ww w.ja  va 2s.  c o m
            printJob.print();
        } catch (PrinterException ex) {
            ex.printStackTrace();
        }
    }
}

From source file:org.eurocarbdb.application.glycoworkbench.plugin.PeakAnnotationCalibrationPanel.java

public void onPrint() {
    PrinterJob pj = theWorkspace.getPrinterJob();
    if (pj == null)
        return;/*from   w  w w .  j av  a2 s. com*/

    try {
        pj.setPrintable(theChartPanel);
        if (pj.printDialog())
            pj.print();
    } catch (Exception e) {
        LogUtils.report(e);
    }
}

From source file:org.fhaes.fhfilechecker.FrameViewOutput.java

public void btnPrint_actionPerformed(ActionEvent e) {

    // Get a PrinterJob
    PrinterJob job = PrinterJob.getPrinterJob();
    // Ask user for page format (e.g., portrait/landscape)
    PageFormat pf = job.pageDialog(job.defaultPage());
    // Specify the Printable is an instance of
    // PrintListingPainter; also provide given PageFormat
    job.setPrintable(new PrintListingPainter(out_file_name), pf);
    // Print 1 copy
    job.setCopies(1);//from ww  w .j av a 2 s  . co  m
    // Put up the dialog box
    if (job.printDialog()) {
        // Print the job if the user didn't cancel printing
        try {
            job.print();
        } catch (Exception ex) {
            /* handle exception */}
    }
}

From source file:com.alvermont.terraj.stargen.ui.SystemFrame.java

private void printMenuItemActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_printMenuItemActionPerformed
{//GEN-HEADEREND:event_printMenuItemActionPerformed

    try {//from w  w  w  . j a  va2  s  .  c  om
        List<BufferedImage> images = UIUtils.getPlanetImages(this.planets);

        BufferedImage collage = UIUtils.combineImagesHorizontal(images);

        final PrinterJob printJob = PrinterJob.getPrinterJob();
        final PageFormat pf = printJob.pageDialog(printJob.defaultPage());

        printJob.setPrintable(new ImagePrinter(collage, pf), pf);

        if (printJob.printDialog()) {
            printJob.print();
        }
    } catch (Exception e) {
        log.error("Error printing", e);

        JOptionPane.showMessageDialog(this, "Error: " + e.getMessage() + "\nCheck log file for full details",
                "Error Printing", JOptionPane.ERROR_MESSAGE);
    }

}

From source file:JavaWorldPrintExample2.java

/**
 * Constructor: Example2/*www .  ja  v  a2 s.c  o  m*/
 * <p>
 *  
 */
public JavaWorldPrintExample2() {

    //--- Create a new PrinterJob object
    PrinterJob printJob = PrinterJob.getPrinterJob();

    //--- Create a new book to add pages to
    Book book = new Book();

    //--- Add the cover page using the default page format for this print
    // job
    book.append(new IntroPage(), printJob.defaultPage());

    //--- Add the document page using a landscape page format
    PageFormat documentPageFormat = new PageFormat();
    documentPageFormat.setOrientation(PageFormat.LANDSCAPE);
    book.append(new Document(), documentPageFormat);

    //--- Tell the printJob to use the book as the pageable object
    printJob.setPageable(book);

    //--- Show the print dialog box. If the user click the
    //--- print button we then proceed to print else we cancel
    //--- the process.
    if (printJob.printDialog()) {
        try {
            printJob.print();
        } catch (Exception PrintException) {
            PrintException.printStackTrace();
        }
    }
}

From source file:JavaWorldPrintExample4.java

/**
 * Constructor: Example4//ww w. j  a v  a  2 s.c om
 * <p>
 *  
 */
public JavaWorldPrintExample4() {

    //--- Create a new PrinterJob object
    PrinterJob printJob = PrinterJob.getPrinterJob();

    //--- Create a new book to add pages to
    Book book = new Book();

    //--- Add the cover page using the default page format for this print
    // job
    book.append(new IntroPage(), printJob.defaultPage());

    //--- Add the document page using a landscape page format
    PageFormat documentPageFormat = new PageFormat();
    documentPageFormat.setOrientation(PageFormat.LANDSCAPE);
    book.append(new Document(), documentPageFormat);

    //--- Tell the printJob to use the book as the pageable object
    printJob.setPageable(book);

    //--- Show the print dialog box. If the user click the
    //--- print button we then proceed to print else we cancel
    //--- the process.
    if (printJob.printDialog()) {
        try {
            printJob.print();
        } catch (Exception PrintException) {
            PrintException.printStackTrace();
        }
    }
}