问题
When i press a button in my swt program, a new composite should be drawn. But the composite only displays if i resize the window.
I have a composite (compLoad
) in my gui which is assigned a new composite
compHELP comHelp_ = new compHELP(compLoad, SWT.RESIZE);
i have tried redraw()
but nothing happens
回答1:
The composite needs to be re-layouted when adding/removing controls, see
Composite.layout() // uses Composite.layout(true)
Composite.layout(boolean changed)
Composite.layout(boolean changed, boolean all)
Note that layouts in SWT may cache the preferred size of its controls (determined by Control.computeSize(int w, int h)
). As you are adding new components, a call to layout()
might be sufficient. In cases where the preferred size is likely to have been changed, or the change happens in a sub-composite, use the method with the changed/all
flags to make sure your layout is properly updated.
Side note: when the size of a Composite
is changed, it will be automatically re-layouted (as you noticed when resizing the window).
来源:https://stackoverflow.com/questions/25524074/how-can-i-repaint-a-composite-in-java-swt