Java RCP - Not able to dynamically set text to SWT

2019-08-02 11:08发布

In one of our rcp application's window, I need to set label text dynamically after the creation of the window.

When the window is created I would have created the label control but I would not set the text by then. After user selects a button on the window, I want to set the text of the label inside the button's selection listener method. After setting text to label inside button's selection listener method I am not able to see the text on the window.

Why is that I am not able to see the label text on the window when I set it inside the listener method? Is it because the window is already created?

how do I solve this?

2条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-08-02 11:39

I guess it is something to do with how you layout the label. after setting text on Label, do re-layout or adjust its bounds.

查看更多
三岁会撩人
3楼-- · 2019-08-02 11:45

The Size of the Label is not getting updated after the call to setText(). Try calling parent.layout() after setText() where the parent is the Composite containing your label control.

查看更多
登录 后发表回答