I'm using this for the moment to print out my table, and it works. But I'm not really happy with the layout of the messageformatting, I would like to have both pagenumber and date in the footer, and date format aligned to the left side of the table, and page to the right.
How can I do that? Been reading some stuff about overriding the PrintTable method, but seems to get pretty complex from what I've read.
Hope you can help me with this issue, thank you. :)
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());
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…