如何在动画结束时调用TextInputDialog?

时间:2019-05-28 22:55:27

标签: java javafx

我正在寻找一种解决showAndWait调用问题的方法。 我以为动画处理结束时会触发onFinishedProperty,但仍然无法调用showAndWait,因为错误提示我试图在动画处理期间调用它。动画制作完成后,有没有要立即致电我的对话框?

        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)

0 个答案:

没有答案