How can i repaint a composite in Java (SWT)?

为君一笑 提交于 2019-12-11 20:13:19

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!