我正在尝试在fadein和fadeout之间更改Label的文本,如下所示:
Label label = (Label) this.cardsValueGroup.getChildren().get(1);
label.textProperty().set(String.valueOf(cardsValue));
SequentialTransition t = new SequentialTransition();
if (this.cardsValueGroup.getOpacity() == 1.0) {
FadeTransition fadeOut = new FadeTransition(Duration.seconds(0.5), this.cardsValueGroup);
fadeOut.setFromValue(1.0);
fadeOut.setToValue(0.0);
t.getChildren().add(fadeOut);
}
FadeTransition fadeIn = new FadeTransition(Duration.seconds(0.5), this.cardsValueGroup);
fadeIn.setFromValue(0.0);
fadeIn.setToValue(1.0);
t.getChildren().add(fadeIn);
t.play();
如何添加标签文本转换?
答案 0 :(得分:3)
尝试
fadeOut.setOnFinished(event -> label.setText(...));
或者,如果您仍在使用JavaFX 2,
fadeOut.setOnFinished(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
label.setText(...);
}
});
(在这种情况下你必须让标签成为最终版)。