2

I'm looking for a way around the problem with showAndWait call. I've thought onFinishedProperty is fired when the animation process is over, still im unable to call showAndWait because of error saying that im trying to call it during animation process. Is there anyway to call my dialog right after finish of animation?

        TextInputDialog dialog = new TextInputDialog("Litera");
            dialog.setTitle("");
            dialog.setHeaderText("");
            dialog.setContentText("Wybierz literę:");

            for(int i = 0 ; i<pieChartData.size();i++)
            System.out.println(pieChartData.get(i));
            RotateTransition rotateTransition = new RotateTransition(); 
            rotateTransition.setDuration(Duration.millis(5000)); 
             rotateTransition.setNode(fortuna);       
              rotateTransition.setCycleCount(1);
              rotate.setOnAction(
                      (e)->{
                          fortuna.setRotate(0);
                          rotate.setDisable(true);
                          rotateTransition.setAutoReverse(false); 
                          rotateTransition.setByAngle((int)(Math.random()*10800+360)); 
                          rotateTransition.play(); 
                          rotateTransition.onFinishedProperty().set(new EventHandler<ActionEvent>() {

                              @Override
                              public void handle(ActionEvent event) {
                                  System.out.println(fortuna.getRotate());
                                  Optional<String> result = dialog.showAndWait();
                                  rotate.setDisable(false);
                                  }
                              }

    );
                           });

Exception in thread "JavaFX Application Thread" java.lang.IllegalStateException: showAndWait is not allowed during animation or layout processing
    at javafx.controls/javafx.scene.control.Dialog.showAndWait(Unknown Source)
    at Main$1.handle(Main.java:78)
    at Main$1.handle(Main.java:1)
    at javafx.graphics/javafx.animation.Animation.finished(Unknown Source)
    at javafx.graphics/javafx.animation.AnimationAccessorImpl.finished(Unknown Source)
    at javafx.graphics/com.sun.scenario.animation.shared.SingleLoopClipEnvelope.timePulse(Unknown Source)
    at javafx.graphics/javafx.animation.Animation.doTimePulse(Unknown Source)
    at javafx.graphics/javafx.animation.Animation$1.lambda$timePulse$0(Unknown Source)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at javafx.graphics/javafx.animation.Animation$1.timePulse(Unknown Source)
    at javafx.graphics/com.sun.scenario.animation.AbstractMasterTimer.timePulseImpl(Unknown Source)
    at javafx.graphics/com.sun.scenario.animation.AbstractMasterTimer$MainLoop.run(Unknown Source)
    at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.pulse(Unknown Source)
    at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.pulse(Unknown Source)
    at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.pulseFromQueue(Unknown Source)
    at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.lambda$runToolkit$11(Unknown Source)
    at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(Unknown Source)
    at java.base/java.lang.Thread.run(Unknown Source)
Loli.lover
  • 21
  • 1
  • 2
    You might consider using `Platform.runLater` in `onFinishedProperty` to place the dialog code onto the next cycle of event processing. This may give the API time to update the state more accurately (and take you out of the animation cycle) – MadProgrammer May 28 '19 at 23:02
  • Could you use `show()` and `dialog.setOnHidden(e -> rotate.setDisable(false))`? Another option, I believe, might be to use [this approach](https://stackoverflow.com/questions/46369046/how-to-wait-for-user-input-on-javafx-application-thread-without-using-showandwai); you would start the animation, enter a nested event loop, and then exit the nested event loop in the `onFinished` handler. – Slaw May 28 '19 at 23:06
  • @MadProgrammer actually im very thankful for ur response, Platform.runLater seems to work as intedent, no more problems with dialog call. – Loli.lover May 28 '19 at 23:45
  • @Slaw using show() is causing freeze of program. – Loli.lover May 28 '19 at 23:47
  • I can't reproduce that problem. However, MadProgrammer's approach seems simpler and more straightforward; if it works for you I suggest just using it. – Slaw May 29 '19 at 02:35

0 Answers0