List of usage examples for java.awt.print PrinterJob setPrintable
public abstract void setPrintable(Printable painter, PageFormat format);
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 w w w. ja v a 2s . 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 {//from w w w . j av a 2 s . c o m printJob.print(); } catch (PrinterException ex) { ex.printStackTrace(); } } }
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 v a 2s . 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: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); // 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 {//from w ww .j a va2s. c om job.print(); } catch (PrinterException e) { JOptionPane.showMessageDialog(this, e.toString(), "PrinterException", JOptionPane.ERROR_MESSAGE); } } }
From source file:org.gumtree.vis.core.internal.SWTChartComposite.java
/** * Creates a print job for the chart./*w w w . java2 s . c o m*/ */ @Override public void createChartPrintJob() { final PrinterJob job = PrinterJob.getPrinterJob(); PageFormat pf = job.defaultPage(); pf.setOrientation(PageFormat.LANDSCAPE); // PageFormat pf2 = job.pageDialog(pf); PageFormat pf2 = job.defaultPage(); pf2.setOrientation(PageFormat.LANDSCAPE); if (pf2 != pf) { Printable print = new MyPrintable(); job.setPrintable(print, pf2); if (job.printDialog()) { getDisplay().asyncExec(new Runnable() { public void run() { try { job.print(); } catch (PrinterException e) { MessageBox messageBox = new MessageBox(getShell(), SWT.OK | SWT.ICON_ERROR); messageBox.setMessage(e.getMessage()); messageBox.open(); } } }); } } // PrintDialog dialog = new PrintDialog(getShell()); // // Prompts the printer dialog to let the user select a printer. // PrinterData printerData = dialog.open(); // // if (printerData == null) // the user cancels the dialog // return; // // Loads the printer. // final Printer printer = new Printer(printerData); // getDisplay().asyncExec(new Runnable(){ // // public void run() { // print(printer); // printer.dispose(); // }}); }
From source file:org.gumtree.vis.awt.CompositePanel.java
@Override public void createChartPrintJob() { setCursor(StaticValues.WAIT_CURSOR); PrinterJob job = PrinterJob.getPrinterJob(); PageFormat pf = job.defaultPage(); PageFormat pf2 = job.pageDialog(pf); if (pf2 != pf) { job.setPrintable(this, pf2); try {//from www .j a v a 2s . com job.print(); } catch (PrinterException e) { JOptionPane.showMessageDialog(this, e); } finally { setCursor(StaticValues.defaultCursor); } } setCursor(StaticValues.defaultCursor); }
From source file:com.sshtools.sshterm.SshTermSessionPanel.java
/** * *//* w w w. jav a2 s . c om*/ public void printScreen() { try { PrinterJob job = PrinterJob.getPrinterJob(); job.setPrintable(terminal, pageFormat); if (job.printDialog()) { setCursor(Cursor.getPredefinedCursor(3)); job.print(); setCursor(Cursor.getPredefinedCursor(0)); } } catch (PrinterException pe) { JOptionPane.showMessageDialog(this, pe.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } }
From source file:org.gvsig.remotesensing.scatterplot.chart.ScatterPlotDiagram.java
/** * Creates a print job for the chart.//from w w w .j av a 2 s. c o m */ public void createChartPrintJob() { PrinterJob job = PrinterJob.getPrinterJob(); PageFormat pf = job.defaultPage(); PageFormat pf2 = job.pageDialog(pf); if (pf2 != pf) { job.setPrintable(this, pf2); if (job.printDialog()) { try { job.print(); } catch (PrinterException e) { JOptionPane.showMessageDialog(this, e); } } } }
From source file:com.sshtools.sshterm.SshTerminalPanel.java
public void printScreen() { try {//from w w w .ja v a 2 s . c om PrinterJob job = PrinterJob.getPrinterJob(); job.setPrintable(terminal, pageFormat); if (job.printDialog()) { setCursor(Cursor.getPredefinedCursor(3)); job.print(); setCursor(Cursor.getPredefinedCursor(0)); } } catch (PrinterException pe) { JOptionPane.showMessageDialog(this, pe.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } }
From source file:rulebender.editors.dat.view.CustomizedChartComposite.java
/** * Creates a print job for the chart.//from w w w . ja va2 s .co m */ public void createChartPrintJob() { //FIXME try to replace swing print stuff by swt PrinterJob job = PrinterJob.getPrinterJob(); PageFormat pf = job.defaultPage(); PageFormat pf2 = job.pageDialog(pf); if (pf2 != pf) { job.setPrintable(this, pf2); if (job.printDialog()) { try { job.print(); } catch (PrinterException e) { MessageBox messageBox = new MessageBox(this.canvas.getShell(), SWT.OK | SWT.ICON_ERROR); messageBox.setMessage(e.getMessage()); messageBox.open(); } } } }