title: Why Java always print on Windows default printer?
body: <p>I want to print a JPanel which I've created. But if user wants to choose a printer by PrintDialog, no matter which printer is chosen, it's always printing to the default printer in Windows.</p>
  <p>Here is my code:</p>
  <p>First I create pageBook</p>
  <pre><code>public static Book  pBook = new Book(); 
  
   public static class ReportPage implements Printable{
      @Override
      public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) {
          if (pageIndex &gt;= 1) {
              return Printable.NO_SUCH_PAGE;
          }
          Graphics2D g2d = (Graphics2D) graphics;
          //g2d.scale(0.2275d,0.225d);
          pagePanel.paint(g2d);
  
          return Printable.PAGE_EXISTS;
      }
  }
  </code></pre>
  <p>The print method:</p>
  <pre><code>public static void printReport(){
      PrinterJob pj = PrinterJob.getPrinterJob();
      PageFormat pf = new PageFormat();
      Paper paper   = pf.getPaper();
      pf.setPaper(paper);
      pBook.append(new ReportPage(),pf);
      pj.setPageable(pBook);      
      if (pj.printDialog()) {
          try {pj.print();}
              catch (PrinterException exc){
              System.out.println(exc);
          }
      }   
  }
  </code></pre>