Silver Lee
Silver Lee

Reputation: 21

JavaFX timeline printing

I got an error on JavaFX timeline and printing. I set three frames in timeline, fill-in data in a form , wait 5 seconds and print out the form on A4 paper:

Timeline timeline = new Timeline(
                new KeyFrame(
                        Duration.seconds(0),
                        event -> MakeQR(canvas.getGraphicsContext2D())                         
                ),
                new KeyFrame(Duration.seconds(5)),                 
                new KeyFrame(
                        Duration.seconds(2),
                        event -> print(root))

);

But I got an exception from J2DprinterJob:

Exception("Printing is not allowed during animation or layout processing");

Please advise an possible solution, thank you.

Upvotes: 2

Views: 318

Answers (1)

jewelsea
jewelsea

Reputation: 159331

Looks like the text of this error was added as part of the fixes for:

It would seem from comments on the related bug report that the design is to disallow printing during animation and the fix was just to clarify by documentation the restriction.

The bug report mentions:

The upshot of this is that you will need to change your application code to not call printing from an animation timer. You can do this either by using another mechanism to trigger the printing, or if you really do want to trigger it from an animation timer, then you will need to wrap your calls to printing in a Platform.runLater().

Upvotes: 1

Related Questions