Reputation: 83
I have a pane in my javafxml file named receiptPane. I like to print this pane as it contains tableview, and labels. I know how to print the node but somehow I couldn't figure it out to print the pane. If I a put any node here it works, it prints the node. But, if I put my pane here, it doesn't print out.
@FXML
public void print() {
// Create a printer job for the default printer
PrinterJob job = PrinterJob.createPrinterJob();
if (job != null && job.showPrintDialog(receiptPane.getScene().getWindow())){
boolean success = job.printPage(receiptPane);
if (success) {
job.endJob();
}
}
}
Any help appreciated. Thanks
Upvotes: 1
Views: 1427
Reputation: 83
I was trying to figure out the problem since I asked my question. Here is the reason why do I get blank print. Normally it was printing but it was printing blank. So I tried to create an instance of that pane and add all those nodes inside. It is normally added but, I did that in Scene Builder. I think that was my problem.
So, solution is here below;
receiptPane = new Pane();
receiptPane.getChildren().addAll(totalL,
tAmountL,
dateTimeL,
orderIDL,
compNameL,
compAddress1L,
compAddress2L,
thanksL,
paymentType1L,
paymentTypeAmount1L,
dueL,
dueAmountL,
ordReceipts
);
PrinterJob job = PrinterJob.createPrinterJob();
if (job != null && job.showPrintDialog(receiptPane.getScene().getWindow())){
boolean success = job.printPage(receiptPane);
if (success) {
job.endJob();
}
}
Now, It works.
Thanks for anyone interested.
Upvotes: 1