javafx gui中的闪烁标签 [英] Flashing label in javafx gui

查看:211
本文介绍了javafx gui中的闪烁标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在javafx中让标签在0.1秒内闪烁。该文本显示在后台运行的ImageView gif之上。我将如何进行此操作或者您对最佳方法有任何建议?

I'm looking to make a label blink in and out ever 0.1 seconds in javafx. The text appears on top of an ImageView gif that is running in the background. How would I go about doing this or if you have any suggestions on the best method?

谢谢

推荐答案

虽然@ fabian的解决方案很好,但在这种情况下,您可以使用 FadeTransition 。它改变了节点的不透明度,非常适合你的情况。

Although @fabian's solution is nice, in this case, you could use a FadeTransition. It alters the opacity of the node and is a good fit for your case.

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 gui中的闪烁标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆