3 Replies Latest reply on Apr 28, 2011 6:51 AM by StanislavL

    PrinterJob.pageDialog() really slow.

      When I run the following small program it takes forever for the pageDialog to return. The measured time that is printed out is between 15 and 20 seconds. A couple of those seconds are accounted for by the time it takes for the dialog to show and for me to press the OK button. But after pressing the OK button, it still takes 10-15 seconds for the method to return.

      I don't know if this has anything with the configuration / installed printers on my computer, but when I invoke the page setup from other applications (non-Java), I do not experience this problem. So I believe that this is a problem with Java, not my computer.
      package bug.pagedialog;
      import java.awt.Dimension;
      import java.awt.event.ActionEvent;
      import java.awt.event.ActionListener;
      import java.awt.print.PageFormat;
      import java.awt.print.PrinterJob;
      import javax.swing.JButton;
      import javax.swing.JFrame;
      import javax.swing.SwingUtilities;
      public class PageDialogTest extends JButton implements Runnable {
           * @param args the command line arguments
          public static void main(String[] args) {
              SwingUtilities.invokeLater(new PageDialogTest());
          public void run() {
              setText("Page Dialog");
              setPreferredSize(new Dimension(200, 144));
              addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent e) {
                      long startTime = System.currentTimeMillis();
                      PrinterJob pjob = PrinterJob.getPrinterJob();
                      PageFormat pf = pjob.defaultPage();
                      pf = pjob.pageDialog(pf);
                      System.out.println("Time =" + (System.currentTimeMillis() - startTime));
              JFrame jFrame = new JFrame("Demo");
      Edited by: user8478974 on Apr 27, 2011 2:18 PM
        • 1. Re: PrinterJob.pageDialog() really slow.
          I've met similar problems. There were 2 cases of such a problem. First one was incorrectly installed printer driver. Updating to newer version fixed the problem. The second case was network printer(s) not available because of switched off computers/network problems etc.
          • 2. Re: PrinterJob.pageDialog() really slow.

            I am suspecting that after the page format has been updated, there is some attempt to communicate with all installed printers, and that that is the reason for the delay. And it is possible that my printer(s) have been incorrectly installed, but I doubt it because then I should experience other problems and the same kind of delay when I change the page setup from e.g., my web browser, which I don't. So I am suspecting a bug somewhere in Java.

            After posting my previous message, I installed JDK 7.0, and under this jdk the problem is gone! I have even stronger reasons to believe that there is a bug in Java v 6.0. Should I report it?
            • 3. Re: PrinterJob.pageDialog() really slow.
              I think no need to report if it's already fixed in java 7.
              1 person found this helpful