如何在Java(SWT)中重新粉刷合成物? [英] How can i repaint a composite in Java (SWT)?
问题描述
当我在我的swt程序中按一个按钮时,应该绘制一个新的合成物.但是,复合材料仅在我调整窗口大小时显示.
我在gui中有一个合成(compLoad
),它被分配了一个新的合成
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);
我尝试了redraw()
,但没有任何反应
i have tried redraw()
but nothing happens
推荐答案
添加/删除控件时,需要重新布置复合结构,请参见
Composite.layout() // uses Composite.layout(true)
Composite.layout(boolean changed)
Composite.layout(boolean changed, boolean all)
请注意,SWT中的布局可能缓存其控件的首选大小(由layout()
的调用可能就足够了.如果首选尺寸可能已更改,或者更改发生在子复合材料中,请使用带有changed/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.
旁注:更改Composite
的大小时,它将自动重新布局(如在调整窗口大小时所注意到的那样).
Side note: when the size of a Composite
is changed, it will be automatically re-layouted (as you noticed when resizing the window).
这篇关于如何在Java(SWT)中重新粉刷合成物?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!