В моей программе есть кнопка «Печать изображения», которая отправляет содержимое узла imageView на принтер.Кнопка вызывает отображение диалогового окна печати.
Проблема заключается в том, что внутри диалогового окна независимо от того, нажимаете ли вы кнопку Печать, Отмена или кнопку X, документ все еще печатается.Как это исправить, чтобы документ печатался только после подтверждения в диалоговом окне печати?
// a method that allows user to print the contents of the ImageView node
@FXML
private void printImageView(ActionEvent event) {
if (imageDisplay.getImage() == null) {
event.consume();
return;
} else {
// create a new image view node and send the image there
ImageView printedImageView = new ImageView();
printedImageView.setImage(imageDisplay.getImage());
// instantiate a printer object
PrinterJob printerJob = PrinterJob.createPrinterJob();
// show the print dialog
final Scene scene = textArea.getScene();
final Window owner = scene.getWindow();
printerJob.showPrintDialog(owner);
// end the job if print is successful
boolean successfullyPrinted = printerJob.printPage(printedImageView);
if (successfullyPrinted) {
printerJob.endJob();
}
}
}