java - JavaFX 标签的 FillTransition
问题描述
有没有办法可以为标签制作类似 FillTransition 的东西?
我基本上只是想以动画方式更改 Label 的文本颜色。
已经谢谢你了!
解决方案
一个简单的解决方案是使用Text
节点而不是Label
. Text
扩展Shape
,因此可以与 a 一起使用FillTransition
。另一方面,您失去了添加背景和省略号功能的可能性。
如果您想继续使用 a ,我建议使用 a 为属性设置Label
动画。textFill
Timeline
例子:
@Override
public void start(Stage primaryStage) throws Exception {
Color fromColor = Color.BLACK;
Color toColor = Color.ORANGE;
Label label = new Label("hello world!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
Timeline timeline = new Timeline(
new KeyFrame(Duration.ZERO, new KeyValue(label.textFillProperty(), fromColor)),
new KeyFrame(Duration.seconds(10), new KeyValue(label.textFillProperty(), toColor))
);
timeline.play();
Scene scene = new Scene(new StackPane(label));
primaryStage.setScene(scene);
primaryStage.show();
}
推荐阅读
- typescript - 是否可以在 TypeScript 中正确键入具有额外行为的生成器函数?
- python - 无法从“dolfin”导入名称“log”
- x86 - JIT 编译器的 ELF 文件结构是什么?
- sql - SQL Server 中 Postgres 的窗口别名的等价物
- solidity - 带有 Ethers.js 的 Solidity 后备功能
- node.js - 如何正确组织快速端点
- c++ - Boost c++的序列化
- mysql - 如何查询没有直接关系的不同表并组合不明确的列
- python - 在验证数据集上查找预测分类
- css - 样式 ShinyDashboardPlus 旋转木马 - 额外的矩形