开发者

SWT label size is not correctly updated

I'm new in Java/SWT. I'm experiencing some troubles using a SWT label.

When I update the text on the la开发者_StackOverflow中文版bel, its size is not correctly updated (the label is cut, respecting the original size). However, if I perform a very small resize in my dialog, the size is updated correctly.

Basically, I create the label with a default text and then, when I load data I update the label with the real text, that is bigger than the original one.

I tried calling label.update() and label.redraw() without luck.


Try to call parent.layout(), where parent is the Composite which contains your label. Also see Understanding Layouts in SWT.


I know this is old, but in order to not lose any LayoutData settings that may be set on the controls. You should call getParent().requestLayout(). The documentation specifically discourages the user of getParent().layout() which loses all the cached Data settings on the controls.


Use of this method is discouraged since it is the least-efficient way to trigger a layout. The use of layout(true) discards all cached layout information, even from controls which have not changed. It is much more efficient to invoke Control.requestLayout() on every control which has changed in the layout than it is to invoke this method on the layout itself.

Based on the documentation of getParent().layout(), you should call requestLayout() on the control itself not its parent as @kingargyle said.

What I always did was label.requestLayout() and it worked flawlessly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜