I want to print my tableView onto a A4 in Landscape format. I also want the tableView to scale itselfe on to this A4 page.
I managed to do this:
Printer printer = Printer.getDefaultPrinter();
PrinterJob printerJob = PrinterJob.createPrinterJob();
//set layout to A4 and landscape
PageLayout pageLayout = printer.createPageLayout(Paper.A4,
PageOrientation.LANDSCAPE, Printer.MarginType.DEFAULT);
printerJob.getJobSettings().setPageLayout(pageLayout);
System.out.println(pageLayout.getPrintableWidth());
System.out.println(pageLayout.getPrintableHeight());
final double scaleX = pageLayout.getPrintableWidth() / _menuPlanTable.getBoundsInParent().getWidth();
final double scaleY = pageLayout.getPrintableHeight() / _menuPlanTable.getBoundsInParent().getHeight();
_menuPlanTable.getTransforms().add(new Scale(scaleX, scaleY));
if(printerJob.showPrintDialog(_controlStage) && printerJob.printPage(_menuPlanTable)) {
_menuPlanTable.getTransforms().remove(getTransforms().size());
printerJob.endJob();
}
else{
_menuPlanTable.getTransforms().remove(getTransforms().size());
}
The result looks like this: IMAGE
You can clearly see that my table is cut off and the right bound is alot bigger than the left.
Any tipps?