How to force redrawing ex-invisible group content in SWT?

I'm a complete noob in SWT, just getting started, but previously worked with GUIs like Swing.

I have a Composite that contains a group and a button. The group is initially set to invisible (using group.setVisible (false)), and when you click the button, it becomes visible. This starts a thread that does some calculations, updating the label inside the group with progress (like a manual progress bar. This is what the client wants :)).

In any case, for some reason, the group appears only after the thread has completed execution, and I can not seem to appear, regardless of what I used (I tried calling this.pack (), this.layout ( ), this.getShell (). layout (), redraw () for the various controls in the path - nothing).

This is how I create a group:

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

This is how I update it from 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);
}

Any hint would be appreciated.

+2
source share
1 answer

Apparently the solution is to use Display.getCurrent().update();

+1
source

Source: https://habr.com/ru/post/1713497/


All Articles