简体   繁体   English

Java RCP-无法将文本动态设置为SWT标签控件

[英]Java RCP - Not able to dynamically set text to SWT label control

In one of our rcp application's window, I need to set label text dynamically after the creation of the window. 在我们的rcp应用程序窗口之一中,我需要在创建窗口后动态设置标签文本。

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? 我该如何解决?

The Size of the Label is not getting updated after the call to setText() . 调用setText()后,Label的大小不会更新。 Try calling parent.layout() after setText() where the parent is the Composite containing your label control. 尝试在setText() parent.layout()之后调用parent.layout() ,其中parent是包含标签控件的Composite

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. Label上设置文本后,请重新布局或调整其边界。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM