我正在尝试在单个打印作业中将 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);
}
}
我的问题是,这只会打印添加到 Book 的第一个 Printable ;在这种情况下,JTable。如果我交换订单并先添加面板,那么它只会打印面板。有人可以指出错误吗?