2013-04-03 60 views
0

我想一個JTable和一個JPanel發送到打印機在一次打印作業是這樣的:打印多個組件

  PrintRequestAttributeSet attr = new HashPrintRequestAttributeSet(); 
      attr.add(OrientationRequested.LANDSCAPE); 

      MessageFormat header = new MessageFormat("Page {0}"); 
      Printable p1 = table.getPrintable(JTable.PrintMode.FIT_WIDTH, header, null); 

      PageFormat pf = new PageFormat();     

      Printable p2 = new ComponentPrinter().returnIt(jPanel1); 

      Book book = new Book(); 
      book.append(p1, pf); 
      book.append(p2, pf); 

      PrinterJob pj = PrinterJob.getPrinterJob(); 

      pj.setPageable(book); 

      if (pj.printDialog(attr)){ 
       try { 
        pj.print(attr); 
       } catch (PrinterException ex) { 
        Exceptions.printStackTrace(ex); 
       } 
      } 

我的問題是,這種只打印第一打印加入書;在這種情況下,JTable。如果我交換訂單並首先添加面板,那麼它只打印面板。有人可以指出錯誤嗎?

+0

任何幫助[here](http://stackoverflow.com/a/10251531/230513)? – trashgod 2013-04-04 08:32:18

+0

不幸的是,沒有。這跟我做的事情差不多。它的確給了我試圖使用printDialog()和print()方法而不是帶參數的方法。打印機對話框顯示2個頁面進行打印,但只打印一個。我嘗試只打印第二頁,但打印作業卡住了。 – 2013-04-04 08:49:35

+0

答案是[here] [here] [here]:http://stackoverflow.com/questions/14775753/printing-multiple-jtables-as-one-job-book-object-only-prints-1start? rq = 1 – 2013-04-05 10:01:19

回答

0

答案在於here

該書將錯誤的pageIndex傳遞給添加的Printables。有關更多信息和解決方案,請點擊鏈接。