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
Been trying some things back and forth now and still not able to get anything to work. I know what I've pasted in here might be a bit (way) off, but it's the result of trying various things.
public class CustomTablePrint implements Printable {
private static CustomTablePrint INSTANCE = null;
public static CustomTablePrint getInstance() {
if (INSTANCE == null) {
INSTANCE = new CustomTablePrint();
}
return INSTANCE;
}
private CustomTablePrint() {}
@Override
public int print(Graphics graphics, PageFormat pageFormat,
int pageIndex) throws PrinterException {
if (pageIndex > 0) {
return NO_SUCH_PAGE;
}
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintable(WindowInventory.getInstance().getTable().getPrintable(JTable.PrintMode.FIT_WIDTH, null, null));
Graphics2D g2d = (Graphics2D)graphics;
g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
// Draw header/footer here
String strDate = MessageFormat.format("{0,date,short} {0,time,short}", new Date());
String printed = "Printed: ";
graphics.drawString(printed + strDate, 10, 10);
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
aset.add(OrientationRequested.LANDSCAPE);
job.printDialog(aset);
return PAGE_EXISTS;
}
}