gpt4 book ai didi

javafx - javafx gui中闪烁的标签

转载 作者:行者123 更新时间:2023-12-03 22:55:52 27 4
gpt4 key购买 nike

我希望在 javafx 中让标签每 0.1 秒闪烁一次。文本显示在后台运行的 ImageView gif 的顶部。我将如何去做,或者您对最佳方法有什么建议?

谢谢

最佳答案

@fabian 的解决方案很好。尽管如此,在这种情况下,您可以使用 FadeTransition .它会改变节点的不透明度,非常适合您的用例。

FadeTransition fadeTransition = new FadeTransition(Duration.seconds(0.1), label);
fadeTransition.setFromValue(1.0);
fadeTransition.setToValue(0.0);
fadeTransition.setCycleCount(Animation.INDEFINITE);
MCVE
import javafx.animation.Animation;
import javafx.animation.FadeTransition;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import javafx.util.Duration;

public class LabelBlink extends Application {

@Override
public void start(Stage primaryStage) throws Exception {
Label label = new Label("Blink");
FadeTransition fadeTransition = new FadeTransition(Duration.seconds(0.1), label);
fadeTransition.setFromValue(1.0);
fadeTransition.setToValue(0.0);
fadeTransition.setCycleCount(Animation.INDEFINITE);
fadeTransition.play();
Scene scene = new Scene(new StackPane(label));
primaryStage.setScene(scene);
primaryStage.show();
}

public static void main(String[] args) {
Application.launch();
}
}

关于javafx - javafx gui中闪烁的标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43084698/

27 4 0