我希望在JavaFX应用程序中为特定时间禁用按钮。是否有此选项?如果没有,是否有任何解决方法?
以下是应用程序中的代码。我尝试了Thread.sleep
,但我知道这不是阻止用户单击下一个按钮的好方法。
nextButton.setDisable(true);
final Timeline animation = new Timeline(
new KeyFrame(Duration.seconds(delayTime),
new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent actionEvent) {
nextButton.setDisable(false);
}
}));
animation.setCycleCount(1);
animation.play();