在淡入和淡出过渡之间更改标签文本

时间:2014-04-10 13:11:51

标签: javafx label transitions

我正在尝试在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();

如何添加标签文本转换?

1 个答案:

答案 0 :(得分:3)

尝试

fadeOut.setOnFinished(event -> label.setText(...));

或者,如果您仍在使用JavaFX 2,

fadeOut.setOnFinished(new EventHandler<ActionEvent>() {
    @Override
    public void handle(ActionEvent event) {
        label.setText(...);
    }
});

(在这种情况下你必须让标签成为最终版)。