繁体   English   中英

Vaadin UI从其他线程更改UI组件时未更新

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM