简体   繁体   English

如何打印 javafx 窗格?

[英]how to print javafx pane?

I have a pane in my javafxml file named receiptPane .我的 javafxml 文件中有一个名为receivePane的窗格。 I like to print this pane as it contains tableview, and labels.我喜欢打印这个窗格,因为它包含 tableview 和标签。 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谢谢

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.它通常是添加的,但是,我在 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.感谢任何有兴趣的人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM