Java examples for 2D Graphics:Print
Displaying the Print Dialog
import java.awt.Graphics; import java.awt.print.PageFormat; import java.awt.print.Printable; import java.awt.print.PrinterException; import java.awt.print.PrinterJob; public class Main { public void m() { PrinterJob pjob = PrinterJob.getPrinterJob(); PageFormat pf = pjob.defaultPage(); pjob.setPrintable(new PrintableClass(), pf); try {/*w w w.j a va 2 s . c o m*/ if (pjob.printDialog()) { pjob.print(); } } catch (PrinterException e) { } } } class PrintableClass implements Printable{ @Override public int print(Graphics arg0, PageFormat arg1, int arg2) throws PrinterException { // TODO Auto-generated method stub return 0; } }