【问题标题】:How to force redraw of an ex-invisible group's content in SWT?如何在 SWT 中强制重绘前不可见组的内容?
【发布时间】:2009-04-12 15:21:19
【问题描述】:

我是 SWT 的菜鸟,刚刚开始,但我之前曾使用过诸如 Swing 之类的 GUI 框架。

我有一个组合,其中包含一个组和一个按钮。 Group 最初设置为不可见(使用 group.setVisible(false)),并在单击按钮时设置为可见。这将启动一个执行一些计算的线程,用进度更新组内的标签(一种手动进度条。这是客户想要的:))。

无论如何,由于某种原因,该组仅在线程完成运行后才会出现,而我似乎无法使其出现,无论我使用什么(尝试调用this.pack(),this.layout ()、this.getShell().layout()、redraw() 对路径中的各种控件 - 无)。

这是我创建组的方式:

statusGroup = new Group(this, SWT.SHADOW_NONE);
statusGroup.setLayout(null);
statusGroup.setVisible(false);
percentCompleteLabel = new Label(statusGroup, SWT.NONE);
percentCompleteLabel.setText("0% complete");

这是我从 Button 的 SelectionListener 更新它的方式:

this.statusGroup.setVisible(true);
this.statusGroup.pack(true);
this.statusGroup.layout();


this.getShell().layout();

myThreadStartupCode(); // psuedo

while (!workIsDone)  // psuedo
{
   final int progress = myProgressCalcMethod();  // psuedo

   percentCompleteLabel.setText(progress + "% complete");
   percentCompleteLabel.pack(true);

   this.layout();
   this.redraw();

   Thread.sleep(100);
}

任何线索将不胜感激。

【问题讨论】:

    标签: java swt


    【解决方案1】:

    显然,解决方案是使用Display.getCurrent().update();

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-02
      • 2012-12-22
      • 2012-08-09
      • 2012-07-19
      • 1970-01-01
      相关资源
      最近更新 更多