JavaFX: How to disable a button for a specific amount of time?

后端 未结 4 1116
轻奢々
轻奢々 2021-01-13 10:48

I want to disable a button for a specific time in JavaFX application. Is there any option to do this? If not, is there any work around for this?

Below is my code in

4条回答
  •  無奈伤痛
    2021-01-13 11:04

    You could also be using the Timeline:

      final Button myButton = new Button("Wait for " + delayTime + " seconds.");
      myButton.setDisable(true);
    
      final Timeline animation = new Timeline(
                new KeyFrame(Duration.seconds(delayTime),
                new EventHandler() {
                    @Override public void handle(ActionEvent actionEvent) {
                        myButton.setDisable(false);
                    }
                }));
      animation.setCycleCount(1);
      animation.play();
    

提交回复
热议问题