我目前正在使用它来打印我的表格,并且它有效。但我对消息格式的布局并不满意,我希望页脚和日期都在页脚中,日期格式与表格左侧对齐,页面在右侧。
我怎样才能做到这一点?一直在阅读一些关于覆盖 PrintTable 方法的内容,但从我所读到的内容似乎变得相当复杂。
希望你能帮我解决这个问题,谢谢。:)
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.PrintRequestAttributeSet;
import javax.print.attribute.standard.OrientationRequested;
import javax.swing.JTable;
import dk.beesys.rims.ui.WindowInventory;
public class Print {
private static Print INSTANCE;
public static Print getInstance() {
if (INSTANCE == null) {
INSTANCE = new Print();
}
return INSTANCE;
}
private Print(){ }
public void printList(java.awt.event.ActionEvent ignore) {
String strDate = MessageFormat.format("{0,date,short} {0,time,short}", new Date());
MessageFormat header = new MessageFormat("- {0} -");
MessageFormat footer = new MessageFormat("Printed: " + strDate);
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
aset.add(OrientationRequested.LANDSCAPE);
try {
WindowInventory.getInstance().getTable().print(JTable.PrintMode.FIT_WIDTH, header, footer, true, aset, true);
} catch (java.awt.print.PrinterException e) {
System.err.format("Cannot print %s%n", e.getMessage());
}
}