Displaying the Print Dialog - Java 2D Graphics

Java examples for 2D Graphics:Print

Description

Displaying the Print Dialog

Demo Code

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;
  }
  
}

Related Tutorials