我正在使用它来打印出我的表格,并且它可以正常工作。但我对消息格式的布局并不满意,我希望在页脚中包含页码和日期,日期格式与表格的左侧对齐,并且页面在右侧。在打印JTable时对齐消息格式
我该怎么做?一直在阅读一些关于重写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());
}
}
一直试图让它工作,但没有任何运气。任何人都有可能比上面的CustomTablePrintable示例更容易实现的代码示例的机会? – DanielFH 2010-02-23 08:19:39