Open Print Dialog in Java

Description

The following code shows how to open Print Dialog.

Example


/*ww w. ja v  a2  s. c o m*/


import java.awt.print.PageFormat;
import java.awt.print.PrinterJob;

public class Main {
  public static void main(String[] argv) throws Exception {

    PrinterJob pjob = PrinterJob.getPrinterJob();
    PageFormat pf = pjob.defaultPage();
    pjob.setPrintable(null, pf);

    if (pjob.printDialog()) {
      pjob.print();
    }

  }
}

The code above generates the following result.

Open Print Dialog in Java




















Home »
  Java Tutorial »
    Graphics »




Animation
BufferedImage
Color
Font
Gradient
Graphics Settings
Image
Mouse Draw
Print
Shape
Text
Transform