[英]Vaadin UI not updating while changing UI components from another thread
我在普通的私有函數中有以下代碼片段,該代碼片段是從同一類的另一種方法調用的(該類稱為AdministrationComponent
,它extends CustomComponent
)。 此組件已添加到TabBarView
。 我的問題是,您在代碼中看到的三個標簽沒有更新。
new Thread(new Runnable()
{
@Override
public void run()
{
while (true)
{
try
{
Thread.sleep(2000);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
Runnable uiRunnable = () -> {
DSCXPSStatusInformation dsi = xpsService.getDSCXPSStatusInformation();
totalSpaceLabel.setValue(String.valueOf(dsi.getTotalSpaceInMB()) + " MB");
spaceLeftLabel.setValue(String.valueOf(dscxpsStatusInformation.getLeftSpaceInMB()) + " MB");
uptimeLabel.setValue(String.valueOf(dscxpsStatusInformation.getUptimeInSec()) + " sec");
};
UI.getCurrent().access(uiRunnable);
UI.getCurrent().push();
}
}
}).start();
請閱讀vaadin書中有關Push的部分
您需要啟用推送,以便Web服務器可以將有關UI更改的信息通知Web瀏覽器。
我找到了答案:我使用的是dscxpsStatusInformation
而不是dsi
。 我不知道為什么月食沒有錯誤。 我在dscxpsStatusInformation
任何地方都沒有dscxpsStatusInformation
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.