如何在 java fx 和打印节点中显示打印对话框

How to display print dialog in java fx and print node

我想在打印前显示一个对话框,以便用户可以选择他们喜欢的打印机,并在可能的情况下更改页面设置, 我在桌面环境(Windows 8 64 位)中使用 Java 8 update 31,我当前的代码是这样的

Node node = new Circle(100, 200, 200);
PrinterJob job = PrinterJob.createPrinterJob();
if (job != null) {
boolean success = job.printPage(node);
if (success) {
    job.endJob();
}
}

您可以使用 PrinterJob 的 showPrintDialog 方法。

PrinterJob job = PrinterJob.createPrinterJob();
if (job != null && job.showPrintDialog(node.getScene().getWindow())){
    boolean success = job.printPage(node);
    if (success) {
        job.endJob();
    }
}