如何更改JavaFX标签';用关键帧填充文本?

如何更改JavaFX标签';用关键帧填充文本?,java,javafx,javafx-8,Java,Javafx,Javafx 8,因此,我通常理解关键帧构造函数接受节点属性和所需的结束值 例如: 新关键帧(Duration.seconds(2),新KeyValue(YourNode.layoutXProperty,75)) 但是,Label.textFill不存在,并且getTextFill是一个getter,而不是一个成员变量。有没有办法绕过这个问题 代码的工作原理如下: 新的关键帧(Duration.seconds(2),新的KeyValue(YourNode.textFill,Color.GREEN)) 类型为T的J

因此,我通常理解关键帧构造函数接受节点属性和所需的结束值

例如:

新关键帧(Duration.seconds(2),新KeyValue(YourNode.layoutXProperty,75))

但是,Label.textFill不存在,并且getTextFill是一个getter,而不是一个成员变量。有没有办法绕过这个问题

代码的工作原理如下:

新的关键帧(Duration.seconds(2),新的KeyValue(YourNode.textFill,Color.GREEN))


类型为
T
的JavaFX属性
xxx
的方法命名模式为:

public Property<T> xxxProperty() // returns the property itself
public T getXxx() // returns the value of the property
public void setXxx(T x) // sets the value of the property
SSCCE:

import javafx.animation.Animation;
import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import javafx.util.Duration;

public class TextFillTransition extends Application {

    @Override
    public void start(Stage primaryStage) {
        Label label = new Label("Transitioning the fill of a label");
        label.setStyle("-fx-font-size: 24pt ;");

        Timeline timeline = new Timeline(
            new KeyFrame(Duration.seconds(0), new KeyValue(label.textFillProperty(), Color.RED)),
            new KeyFrame(Duration.seconds(2), new KeyValue(label.textFillProperty(), Color.GREEN))
        );
        timeline.setAutoReverse(true);
        timeline.setCycleCount(Animation.INDEFINITE);
        timeline.play();

        StackPane root = new StackPane(label);
        root.setPadding(new Insets(12));
        primaryStage.setScene(new Scene(root));
        primaryStage.show();
    }

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

?您是对删除的问题的最后一个评论——是的,要求可能看起来是任意的,但请理解,网站已经发展并将继续发展,包括对问题的要求。你提供的链接是在这个网站刚刚起步的时候问到的一个问题,目前的规则不适用。从那时起,这些规则再次发生了变化,但为了帮助海报,在该部分的各个链接中对它们进行了详细描述。此外,规则和这些规则的微调也在不断发展,这主要在网站的元部分中讨论,其中。。。。。。。我邀请你们去看看,并为这些完全有意义的项目做出贡献。我对这些规则的讨论非常感兴趣,我对什么是可接受的/不可接受的有了更好的理解,因为我越来越多地参与到个人项目中,我学得很快,并且希望成为社区中更积极的一员。@hoverfullofeels规则随着时间的推移而演变是可以理解的,我本来没有查过那篇文章上的日期。顺便说一句,那个链接不是一个gotcha,我在问我的问题之前最初搜索时才找到它,而这个问题的样式让我觉得我的问题具有适当的深度和特殊性。啊,这是完全正确的。不知道为什么我最初找不到它,但这完全有道理。非常感谢。
import javafx.animation.Animation;
import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import javafx.util.Duration;

public class TextFillTransition extends Application {

    @Override
    public void start(Stage primaryStage) {
        Label label = new Label("Transitioning the fill of a label");
        label.setStyle("-fx-font-size: 24pt ;");

        Timeline timeline = new Timeline(
            new KeyFrame(Duration.seconds(0), new KeyValue(label.textFillProperty(), Color.RED)),
            new KeyFrame(Duration.seconds(2), new KeyValue(label.textFillProperty(), Color.GREEN))
        );
        timeline.setAutoReverse(true);
        timeline.setCycleCount(Animation.INDEFINITE);
        timeline.play();

        StackPane root = new StackPane(label);
        root.setPadding(new Insets(12));
        primaryStage.setScene(new Scene(root));
        primaryStage.show();
    }

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