gpt4 book ai didi

java - 如何打印javafx Pane ?

转载 作者:行者123 更新时间:2023-11-30 06:06:21 25 4
gpt4 key购买 nike

我的 javafxml 文件中有一个名为 receiptPane 的 Pane 。我喜欢打印这个 Pane ,因为它包含表格 View 和标签。我知道如何打印节点,但不知何故我无法弄清楚如何打印 Pane 。如果我将任何节点放在这里,它就会工作,它会打印该节点。但是,如果我将 Pane 放在这里,它就不会打印出来。

@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();
}
}
}

任何帮助表示赞赏。谢谢

最佳答案

自从我提出问题以来,我一直在试图找出问题所在。这就是我得到空白打印的原因。正常情况下是打印的,但是打印出来是空白的。因此,我尝试创建该 Pane 的一个实例,并在其中添加所有这些节点。它通常是添加的,但我是在场景生成器中添加的。我认为这是我的问题。

所以,解决方案如下;

 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();
}
}

现在,它可以工作了。

感谢任何感兴趣的人。

关于java - 如何打印javafx Pane ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51233470/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com