Dav*_*oor 0 label javafx transitions
我正在尝试在淡入和淡出之间更改标签的文本,如下所示:
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();
Run Code Online (Sandbox Code Playgroud)
如何添加标签文本过渡?
尝试
fadeOut.setOnFinished(event -> label.setText(...));
Run Code Online (Sandbox Code Playgroud)
或者,如果您仍在使用 JavaFX 2,
fadeOut.setOnFinished(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
label.setText(...);
}
});
Run Code Online (Sandbox Code Playgroud)
(在这种情况下,您必须将 label 设为 final)。
| 归档时间: |
|
| 查看次数: |
1352 次 |
| 最近记录: |