Reputation: 1077
I'm trying to change a Label's text in between fadein and fadeout as followed:
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();
How can I add Label text transition as well?
Upvotes: 0
Views: 1459
Reputation: 209418
Try
fadeOut.setOnFinished(event -> label.setText(...));
Or if you're still using JavaFX 2,
fadeOut.setOnFinished(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
label.setText(...);
}
});
(you have to make label final in this case).
Upvotes: 5