List of usage examples for java.awt.print PrinterJob pageDialog
public PageFormat pageDialog(PrintRequestAttributeSet attributes) throws HeadlessException
From source file:Main.java
public static void main(String[] argv) throws Exception { PrinterJob pjob = PrinterJob.getPrinterJob(); PageFormat pf = pjob.defaultPage(); pf.setOrientation(PageFormat.LANDSCAPE); pf = pjob.pageDialog(pf); }
From source file:Main.java
public static void main(String args[]) { try {//from ww w. j a va 2 s . co m String cn = UIManager.getSystemLookAndFeelClassName(); UIManager.setLookAndFeel(cn); // Use the native L&F } catch (Exception cnf) { } PrinterJob job = PrinterJob.getPrinterJob(); PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); PageFormat pf = job.pageDialog(aset); job.setPrintable(new Main(), pf); boolean ok = job.printDialog(aset); if (ok) { try { job.print(aset); } catch (PrinterException ex) { /* The job did not successfully complete */ } } System.exit(0); }
From source file:PrintDialogExample.java
public static void main(String args[]) { try {//from w ww .j a v a 2 s .c o m String cn = UIManager.getSystemLookAndFeelClassName(); UIManager.setLookAndFeel(cn); // Use the native L&F } catch (Exception cnf) { } PrinterJob job = PrinterJob.getPrinterJob(); PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); PageFormat pf = job.pageDialog(aset); job.setPrintable(new PrintDialogExample(), pf); boolean ok = job.printDialog(aset); if (ok) { try { job.print(aset); } catch (PrinterException ex) { /* The job did not successfully complete */ } } System.exit(0); }
From source file:io.github.mzmine.util.jfreechart.JFreeChartUtils.java
public static void printChart(ChartViewer chartNode) { // As of java 1.8.0_74, the JavaFX printing support seems to do poor // job. It creates pixelated, low-resolution print outs. For that // reason, we use the AWT PrinterJob class, until the JavaFX printing // support is improved. SwingUtilities.invokeLater(() -> { PrinterJob job = PrinterJob.getPrinterJob(); PageFormat pf = job.defaultPage(); PageFormat pf2 = job.pageDialog(pf); if (pf2 == pf) return; ChartPanel p = new ChartPanel(chartNode.getChart()); job.setPrintable(p, pf2);// w ww . j av a2s . c o m if (!job.printDialog()) return; try { job.print(); } catch (PrinterException e) { e.printStackTrace(); MZmineGUI.displayMessage("Error printing: " + e.getMessage()); } }); }
From source file:PrintableComponent.java
/** * This method is not part of the Printable interface. It is a method * that sets up the PrinterJob and initiates the printing. *//*from w ww. j a v a2s. c om*/ public void print() throws PrinterException { // Get the PrinterJob object PrinterJob job = PrinterJob.getPrinterJob(); // Get the default page format, then allow the user to modify it PageFormat format = job.pageDialog(job.defaultPage()); // Tell the PrinterJob what to print job.setPrintable(this, format); // Ask the user to confirm, and then begin the printing process if (job.printDialog()) job.print(); }
From source file:playground.artemc.calibration.charts.CustomChartPanel.java
public void createPrintJob() { 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();/* w w w . j a v a 2 s .c om*/ } catch (PrinterException e) { JOptionPane.showMessageDialog(this, e); } } } }
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);//w w w . j a va 2 s . c o 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: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);/* w w w. jav a 2s . c o 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.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 {/* w w w.j ava 2 s.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:com.alvermont.terraj.stargen.ui.SystemFrame.java
private void printMenuItemActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_printMenuItemActionPerformed {//GEN-HEADEREND:event_printMenuItemActionPerformed try {//ww w . j a v a 2 s. c o m 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); } }