Java 合并GridLayout和FillLayout而不添加FormLayout?

Java 合并GridLayout和FillLayout而不添加FormLayout?,java,layout,swt,Java,Layout,Swt,JavaSWT提供了四个标准布局类:FillLayout,RowLayout,GridLayout,FormLayout。我知道如何使用每个布局类,但在组合布局类时会遇到困难 例如,我的应用程序中有一个使用GridLayout的屏幕。我希望添加两个垂直(即FillLayout)布局;一个布局在GridLayout左侧,另一个布局在GridLayout右侧。不幸的是,我无法确定如何获得所需的总体布局(即,请参见底部的ascii艺术) 下面的SO链接给出了一些示例答案,但我希望通过添加FormLay

JavaSWT提供了四个标准布局类:
FillLayout
RowLayout
GridLayout
FormLayout
。我知道如何使用每个布局类,但在组合布局类时会遇到困难

例如,我的应用程序中有一个使用
GridLayout
的屏幕。我希望添加两个垂直(即
FillLayout
)布局;一个布局在
GridLayout
左侧,另一个布局在
GridLayout
右侧。不幸的是,我无法确定如何获得所需的总体布局(即,请参见底部的ascii艺术)

下面的SO链接给出了一些示例答案,但我希望通过添加FormLayout来避免代码更改过多

是否有示例代码允许我在不使用FormLayout的情况下向网格布局添加两个FillLayout?应如下所示(忽略最右侧FillLayout中粘贴不好的ascii)


尝试下面的代码,让我知道如果你是类似的

我对shell使用了
绝对布局
,我在我的应用程序中创建了3个组合,并对2个组合应用了
填充布局
,对1个组合应用了
网格布局
。请参阅下面的代码

public class SampleWindow {

    protected Shell shell;

    /**
     * Launch the application.
     * @param args
     */
    public static void main(String[] args) {
        try {
            SampleWindow window = new SampleWindow();
            window.open();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * Open the window.
     */
    public void open() {
        Display display = Display.getDefault();
        createContents();
        shell.open();
        shell.layout();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch()) {
                display.sleep();
            }
        }
    }

    /**
     * Create contents of the window.
     */
    protected void createContents() {
        shell = new Shell();
        shell.setSize(531, 363);
        shell.setText("SWT Application");

        Composite composite = new Composite(shell, SWT.BORDER);
        composite.setBounds(10, 10, 131, 304);
        composite.setLayout(new FillLayout(SWT.HORIZONTAL));

        Label lblNewLabel = new Label(composite, SWT.NONE);
        lblNewLabel.setText("Fill Layout");

        Composite composite_1 = new Composite(shell, SWT.BORDER);
        composite_1.setBounds(159, 10, 199, 304);
        composite_1.setLayout(new GridLayout(3, false));
        Label lblNewLabel_1 = new Label(composite_1, SWT.NONE);
        lblNewLabel_1.setText("Grid Layout");

        Composite composite_2 = new Composite(shell, SWT.BORDER);
        composite_2.setBounds(382, 10, 123, 304);
        composite_2.setLayout(new FillLayout(SWT.HORIZONTAL));

        Label lblNewLabel_2 = new Label(composite_2, SWT.NONE);
        lblNewLabel_2.setText("Fill Layout");

    }
}
输出类似于以下内容:


因此,您希望在SWT应用程序中添加2个填充布局和一个网格布局,而不添加表单布局。是这样吗?@SubashJ正确。在所有类似的事情上使用
setBounds
通常不是一个好主意。您应该让布局为您处理大小。
public class SampleWindow {

    protected Shell shell;

    /**
     * Launch the application.
     * @param args
     */
    public static void main(String[] args) {
        try {
            SampleWindow window = new SampleWindow();
            window.open();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * Open the window.
     */
    public void open() {
        Display display = Display.getDefault();
        createContents();
        shell.open();
        shell.layout();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch()) {
                display.sleep();
            }
        }
    }

    /**
     * Create contents of the window.
     */
    protected void createContents() {
        shell = new Shell();
        shell.setSize(531, 363);
        shell.setText("SWT Application");

        Composite composite = new Composite(shell, SWT.BORDER);
        composite.setBounds(10, 10, 131, 304);
        composite.setLayout(new FillLayout(SWT.HORIZONTAL));

        Label lblNewLabel = new Label(composite, SWT.NONE);
        lblNewLabel.setText("Fill Layout");

        Composite composite_1 = new Composite(shell, SWT.BORDER);
        composite_1.setBounds(159, 10, 199, 304);
        composite_1.setLayout(new GridLayout(3, false));
        Label lblNewLabel_1 = new Label(composite_1, SWT.NONE);
        lblNewLabel_1.setText("Grid Layout");

        Composite composite_2 = new Composite(shell, SWT.BORDER);
        composite_2.setBounds(382, 10, 123, 304);
        composite_2.setLayout(new FillLayout(SWT.HORIZONTAL));

        Label lblNewLabel_2 = new Label(composite_2, SWT.NONE);
        lblNewLabel_2.setText("Fill Layout");

    }
}