Search code examples
javalayoutcomposite

How make sure that a Composite also lays out its children after calling Composite.layout() in Java


I'm having a Composite with children, which are possibly composites too but can also be other Controls. For Example like this

Composite composite = new Composite(parent, SWT.NONE);
Composite childrenComposite = new Composite(composite, SWT.NONE);
Control childrenChildrenControl = new Control(childrenComposite, SWT.NONE);
Control childrenControl = new Control(composite, SWT.NONE);

And if i call composite.layout() i want that childrenComposite also calls it layout-Method. Is this done automatically? Or do i have to call it separately?

composite.layout();

Solution

  • I found out the following. If u want to make sure that all childrens of a Composite also get layouted use

    Composite composite = new Composite(parent, SWT.NONE);
    Composite childrenComposite = new Composite(composite, SWT.NONE);
    Control childrenChildrenControl = new Control(childrenComposite, SWT.NONE);
    Control childrenControl = new Control(composite, SWT.NONE);
    
    composite.layout(true, true);