开发者

Vertically expandable Composite

开发者 https://www.devze.com 2023-01-17 06:32 出处:网络
I\'m building an SWT UI, and it has a window (Shell) with three Composites stacked one below the other. I want that:

I'm building an SWT UI, and it has a window (Shell) with three Composites stacked one below the other. I want that:

  1. all to expand to the maximum possible width (width of the 开发者_StackOverflowwindow)
  2. the first and third Composites have a height of 100px each
  3. the third composite expand to a height of height_of_parent - 200px - any_margins_or_paddings.

Objective 2 is trivial, and I did Objective 1 using the ColumnLayout defined here.

How do impolement Objective 3?

Many thanks :)

PS: I'm very new to SWT.


I would use a GridLayout and do something like this:

GridLayout layout = new GridLayout();
parent.setLayout(layout);

GridData data1 = new GridData(SWT.LEFT, SWT.FILL, false, true);
data1.heightHint = 100;
widget1.setLayoutData(data1);

GridData data2 = new GridData(SWT.LEFT, SWT.FILL, false, true);
data2.heightHint = 100;
widget2.setLayoutData(data2);

GridData data3 = new GridData(SWT.LEFT, SWT.TOP, false, false);
data3.heightHint = Math.max(1, parent.getSize().y - 200 - layout.marginHeight * 2);
widget3.setLayoutData(data3);

parent.addControlListener(new ControlAdapter() {
    public void controlResized(ControlEvent e) {
        GridData data = (GridData)widget3.getLayoutData();
        data.heightHint = parent.getSize().y - 200 - layout.marginHeight * 2;
        widget3.setLayoutData(data);
        parent.layout(true);
    }
});
0

精彩评论

暂无评论...
验证码 换一张
取 消