private static void printWithCustomImageareaSize() {
final JTable table = createAuthorTable(18);
PrintRequestAttributeSet printAttributes = new HashPrintRequestAttributeSet();
printAttributes.add(DialogTypeSelection.NATIVE);
printAttributes.add(new Copies(1));
printAttributes.add(new MediaPrintableArea(
0.25f, 0.25f, 8.0f, 5.0f, MediaPrintableArea.INCH));
Printable printable = table.getPrintable(
JTable.PrintMode.NORMAL,
new MessageFormat("Author Table"),
new MessageFormat("Page - {0}")
);
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintable(printable);
boolean printAccepted = job.printDialog(printAttributes);
if (printAccepted) {
try {
job.print(printAttributes);
closeFrame();
} catch (Exception e) {
throw new RuntimeException(e);
}
} else {
throw new RuntimeException("User cancels the printer job!");
}
}
ImageableAreaTest.java 文件源码
java
阅读 22
收藏 0
点赞 0
评论 0
项目:jdk8u-jdk
作者:
评论列表
文章目录