HashPrintRequestAttributeSet attributes;
PrinterJob job = PrinterJob.getPrinterJob();
job.setPageable(makeBook());
if(job.printDialog(attributes)){
try {
job.print(attributes);
} catch (PrinterException ex) {
ex.printStackTrace();
}
}上面是我的打印部分代码
在打印对话框里面设置了纸张方向为横向,但打印结果仍然是纵向,
望高手指教。
// fetch the printable
Printable printable = table.getPrintable(JTable.PrintMode.FIT_WIDTH,
new MessageFormat("My Table"),
new MessageFormat("Page - {0}")); // fetch a PrinterJob
PrinterJob job = PrinterJob.getPrinterJob(); // set the Printable on the PrinterJob
job.setPrintable(printable); // create an attribute set to store attributes from the print dialog
PrintRequestAttributeSet attr = new HashPrintRequestAttributeSet(); // display a print dialog and record whether or not the user cancels it
boolean printAccepted = job.printDialog(attr); // if the user didn't cancel the dialog
if (printAccepted) {
// do the printing (may need to handle PrinterException)
job.print(attr);
}
} finally {
// restore the original table state here (for example, restore selection)
}
你代码跟我的没什么区别啊,那个打印设置框里面设置的纸张方向不起作用
必须要先在页面设置里设置过才管用的。