Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [platform-swt-dev] Adding/removing components from a composite at runtime


Unfortunately, a control cannot exist without a parent.  Therefore you can't add and remove it, you have to create and dispose.

I don't think I understand "breaks the current layout".  We fixed the bug that your snippet uncovered (That's what the "Fixed >" thing was about).  Get the latest and try it.  I think you need to read the article http://eclipse.org/articles/Understanding%20Layouts/Understanding%20Layouts.htm to see how layout are supposed to work.  The summary is that you need to call layout() when you add or
remove a control and any other time where you change a property that can affect the preferred size.  

Here are some details:

Layouts only position and resize controls when the parent is resized. The problem with doing it automatically elsewhere is that it's not possible to predict which features of a control affect the preferred size and multiple layouts cause flashing and performance problems. For example, I know that Label.setText() affects the preferred size of a control but what about controls other people write?  In order to support automatic layout when controls are added or removed some kind of deferred layout strategy would be needed, like the painting strategy.  Of course, once you have a deferred strategy, you also need a way to defeat it and force layouts.  All of this is getting farther away from what the operating systems provide, causing problems porting and maintenance problems.

Hope this helps.



"Brad O'Hearne" <brado@xxxxxxxxxxxxx>
Sent by: platform-swt-dev-admin@xxxxxxxxxxx

10/23/2003 09:30 AM
Please respond to platform-swt-dev

       
        To:        "SWT-Dev" <platform-swt-dev@xxxxxxxxxxx>
        cc:        
        Subject:        [platform-swt-dev] Adding/removing components from a composite at runtime



In the wake of a previous thread stating that a Control's setParent() method
is not supported on all platforms, and even on platforms it is supported on,
using it breaks the current layout, is there any way to add/remove child
components from a composite at runtime, and if so, does this operation
maintain the function of the current layout?  I see no add/remove methods
available.

Thanks in advance for your help,

BradO

_______________________________________________
platform-swt-dev mailing list
platform-swt-dev@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/platform-swt-dev


Back to the top