刷新标签无法正常工作javafx [英] refresh label not working correctly javafx
问题描述
我在Label上刷新时遇到问题。
我有这样的函数:
I have a problem with a refresh on a Label. I have an function like this :
public void majMontantPaye(Double montantPaye) {
System.out.println("montant paye : "+montantPaye);
setMontantPaye(this.montantPaye+montantPaye);
Platform.runLater(() -> labelMontantPaye.setText(String.format("%.2f", this.montantPaye)+Messages.getMessage("0052")));
}
我的函数是由API调用的。此API与允许插入硬币的机器通信。我的功能必须显示机器中的总和插入。
And My function is call by an API. This API communicate with a machine who allow to insert coin. And my function must to show the sum insert in the machine.
问题是,当我在机器中同时插入大量硬币时,我的功能是正确调用检测到的每一枚硬币,所以 System.out.println(montant paye:+ montantPaye);
正确显示检测到的每一枚硬币,但标签labelMontantPaye是不刷新检测到的每一枚硬币。刚刚完成总金额。
The problem is, when I insert a lot of coin in the same time in the machine, my function is correctly call every coin detected, so the System.out.println("montant paye : "+montantPaye);
is correctly show every coin detected, BUT the Label "labelMontantPaye" is not refresh to every coin detected. Just on finish with the total sum.
我想UI没有正确刷新,但我不知道我的Label如何正确刷新。
I guess that the UI is not correctly refresh but I don't know how refresh correctly my Label.
请帮忙,对不起,我是法国人。
Help please and sorry for mistake, i'm french.
推荐答案
你可以关注逻辑如下:
如评论中所述:
使用Platform.runLater(...)将任务排入队列JavaFXThread
。但是当你有很多事件时,你只能看到最后的结果。 (也许是之前的短时间内)。
As mentioned in the comments: Using Platform.runLater(...) you queue the task into the
JavaFXThread
. But when you have many "events" you will only see the last result. (And maybe previous ones for a short time).
这篇关于刷新标签无法正常工作javafx的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!