4 Replies Latest reply: Aug 27, 2013 9:23 AM by 4cd8015b-93f2-49c0-8259-a42f97b66045 RSS

    How to disable print Dialog box?

      I want to write the simple program where I don't want to show the
      print dialog box. I am trying to hide it, but don't have any
      proper idea how to disable or hide the print dialog.
      This is the program where i want to print the
      document without prompting user to the print dialog.
      import java.awt.Color;
      import java.awt.Font;
      import java.awt.Graphics;
      import java.awt.Graphics2D;
      import java.awt.print.PageFormat;
      import java.awt.print.Printable;
      import java.awt.print.PrinterException;
      import java.awt.print.PrinterJob;
      public class PrintableDemo1 implements Printable {
          public int print( Graphics g, PageFormat pf, int pageIndex ) {
              if (pageIndex != 0)
                  return NO_SUCH_PAGE;
              Graphics2D g2 = (Graphics2D) g;
              g2.setFont( new Font( "Serif", Font.PLAIN, 36 ) );
              g2.setPaint( Color.black );
              g2.drawString( "Welcome to Java!", 144, 144 );
              return PAGE_EXISTS;
          public static void main( String[] args ) {
              PrinterJob pj = PrinterJob.getPrinterJob();
              pj.setPrintable( new PrintableDemo1() );
              if (pj.printDialog()) {
                  try {
                  } catch (PrinterException e) {
                      System.out.println( e );