在JavaFx Label中显示更改的值 [英] Displaying changing values in JavaFx Label
本文介绍了在JavaFx Label中显示更改的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在JavaFX中,如何使用标签显示随时间不断变化的值?
In JavaFX, how can I display values which continuously change with time using "label" ?
推荐答案
有很多方法可以实现这一点,最方便的是使用JavaFX的DataBinding机制:
There are numerous ways to achieve that, the most convenient would be to use JavaFX's DataBinding mechanism:
// assuming you have defined a StringProperty called "valueProperty"
Label myLabel = new Label("Start");
myLabel.textProperty().bind(valueProperty);
这样,每次通过调用set方法更改valueProperty时,标签的文本都会更新。
This way, every time your valueProperty gets changed by calling it's set method, the label's text is updated.
这篇关于在JavaFx Label中显示更改的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文