Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8097469

Better error checking and docs if Printing or Dialogs called from Animation

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 8u60
    • 8u20
    • javafx
    • Windows 7 64-bit

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

              kcr Kevin Rushforth
              duke J. Duke
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported: