如何确保 Composite 在 Java 中调用 Composite.layout() 后也布置其子项

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

我有一个带有子项的复合体,它们也可能是复合体,但也可以是其他控件。 例如像这样

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(),我希望 childrenComposite 也将其称为布局方法。 这是自动完成的吗? 还是我必须单独调用它?

composite.layout();

我发现了以下内容。 如果你想确保 Composite 的所有孩子也得到布局使用

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);