As of 8u20, calling printPage() from inside an AnimationTimer callback no longer works as it did prior to that. Attempting it results in the following exception:
Exception in thread "JavaFX Application Thread" java.lang.IllegalArgumentException: Key not associated with a running event loop: java.lang.Object@2b4b3670
Here is a sample program illustrating the issue:
public class PrintBugTest extends Application {
@Override
public void start(Stage primaryStage) {
ComboBox<Printer> printerComboBox = new ComboBox<>();
printerComboBox.getItems().addAll(Printer.getAllPrinters());
printerComboBox.getSelectionModel().select(Printer.getDefaultPrinter());
Button btn = new Button("Print");
btn.setOnAction(e -> {
new AnimationTimer() {
@Override
public void handle(long l) {
stop();
Node node = new Circle(100, 200, 200);
PrinterJob job = PrinterJob.createPrinterJob();
job.setPrinter(printerComboBox.getValue());
job.printPage(node);
job.endJob();
}
}.start();
});
VBox root = new VBox();
root.setSpacing(20);
root.setAlignment(Pos.CENTER);
root.setPadding(new Insets(10,10,10,10));
root.getChildren().addAll(new HBox(new Label("Select Printer: "), printerComboBox), btn);
Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.show();
}
}