SWT: notify a composite that it has a new child

*爱你&永不变心* 提交于 2019-12-11 06:39:43

问题


How to notify a Composite if a new child control has been created?

The reason: by default, for the StackLayout no child is shown. I want to ensure that the first control which is added to our StackLayoutComposite (which is a Composite with set StackLayout and a few other helper methods) is shown by default. Currently, I solved it by overriding StackLayout's layout method, but this looks ugly in my eyes.


回答1:


If you want to re-layout the parent Composite based on the new child and any associated layout data, just use composite.layout(true);...

If you want to be notified by the parent that the widget hierarchy has been changed, then you're out of luck... The closest you can get, is to add a SWT filter to the display and wait for a SWT.Resize event for a previously unknown child... I have done this is a project, but I have to admit that the code gets a bit ugly as you have to monitor for disposal as well...



来源:https://stackoverflow.com/questions/6452856/swt-notify-a-composite-that-it-has-a-new-child

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