有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

如何确保在调用Composite后,Composite也会布局其子级。Java中的layout()

我有一个孩子的合成图,可能也是合成图,但也可以是其他控件。 比如像这样

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也调用layout方法。 这是自动完成的吗? 还是我必须单独称呼它

composite.layout();

共 (1) 个答案

  1. # 1 楼答案

    我发现了以下情况。 如果你想确保一个组合中的所有子对象都得到了布局,那么就使用它

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