Java SWT网格布局问题

Java SWT网格布局问题,java,layout,swt,Java,Layout,Swt,所以我一直在做SWT对话。它应该是这样的: /----------------------------------\ | Label1 | | [_Text_box_1__________][Button1] | | | | Label2 | | |---------------------|[Button2] | | | L

所以我一直在做SWT对话。它应该是这样的:

/----------------------------------\
| Label1                           |
| [_Text_box_1__________][Button1] |
|                                  |
| Label2                           |
| |---------------------|[Button2] |
| |  List 1             |[Button3] |
| |---------------------|          |
|                                  |
| Label3                           |
| |---------------------|[Button4] |
| |  List 2             |[Button5] |
| |---------------------|          |
|                                  |
|                 [ Ok ] [ Cancel] |
\----------------------------------/
我已经尝试了文本框+按钮的行布局和嵌套组合,但它似乎没有水平填充空间。我也尝试过GridLayout,包括单列和嵌套组合,以及两列,但它似乎从来都不起作用

有谁能提出一个适合我的方法吗


编辑: 我已设法使其以固定尺寸工作:

    Display display = parent.getDisplay();
    Shell shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL | SWT.TITLE);
    shell.setText("Text");

        RowLayout layout = new RowLayout(SWT.VERTICAL);
        layout.marginBottom = 15;
        layout.marginTop = 15;
        layout.marginLeft = 15;
        layout.marginRight = 15;
        layout.spacing = 5;
        layout.wrap = true;
        layout.fill = true;
        layout.justify = false;
        shell.setLayout(layout);

        Label label1 = new Label(shell, SWT.LEFT);
        label1.setText("Label 1");
        RowData data = new RowData();
        data.width = 400;
        label1.setLayoutData(data);

        Composite comp1 = new Composite(shell, SWT.NONE);
        layout = new RowLayout(SWT.HORIZONTAL);
        layout.fill = true;
        comp1.setLayout(layout);
        Text text1 = new Text(comp1, SWT.SINGLE | SWT.BORDER);
        data = new RowData();
        data.width = 400;
        text1.setLayoutData(data);
        Button button1 = new Button(comp1, SWT.PUSH | SWT.CENTER);
        button1.setText("Button 1");

        new Label(shell, SWT.NONE);

        Label label2 = new Label(shell, SWT.LEFT);
        label2.setText("Label 2");

        Composite comp2 = new Composite(shell, SWT.NONE);
        layout = new RowLayout(SWT.HORIZONTAL);
        comp2.setLayout(layout);

        List list1 = new List(comp2, SWT.BORDER);
        data = new RowData();
        data.width = 400;
        data.height = 150;
        list1.setLayoutData(data);
        Composite comp3 = new Composite(comp2, SWT.NONE);
        comp3.setLayout(new RowLayout(SWT.VERTICAL));
        Button button2 = new Button(comp3, SWT.PUSH | SWT.CENTER);
        button2.setText("Button 2");
        data = new RowData();
        data.width = 70;
        button2.setLayoutData(data);
        Button button3 = new Button(comp3, SWT.PUSH | SWT.CENTER);
        button3.setText("Button 3");
        button3.setLayoutData(data);

        new Label(shell, SWT.NONE);

        Label label3 = new Label(shell, SWT.LEFT);
        label3.setText("Label 3");

        Composite comp4 = new Composite(shell, SWT.NONE);
        layout = new RowLayout(SWT.HORIZONTAL);
        comp4.setLayout(layout);

        List list2 = new List(comp4, SWT.BORDER);
        data = new RowData();
        data.width = 400;
        data.height = 150;
        list2.setLayoutData(data);
        Composite comp5 = new Composite(comp4, SWT.NONE);
        comp5.setLayout(new RowLayout(SWT.VERTICAL));
        Button button4 = new Button(comp5, SWT.PUSH | SWT.CENTER);
        button4.setText("Button 4");
        data = new RowData();
        data.width = 70;
        button4.setLayoutData(data);
        Button button5 = new Button(comp5, SWT.PUSH | SWT.CENTER);
        button5.setText("Button 5");
        button5.setLayoutData(data);

        new Label(shell, SWT.NONE);

        Composite comp6 = new Composite(shell, SWT.RIGHT_TO_LEFT);
        comp6.setLayout(new RowLayout(SWT.HORIZONTAL));
        Button cancelButton = new Button(comp6, SWT.CENTER);
        cancelButton.setText("Cancel");
        data = new RowData();
        data.width = 70;
        cancelButton.setLayoutData(data);
        Button okButton = new Button(comp6, SWT.PUSH | SWT.CENTER);
        okButton.setText("OK");
        okButton.setLayoutData(data);

        shell.pack();
        shell.open();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch())
                display.sleep();
        }

您可以在不依赖宽度提示的情况下实现这一点(只有在没有其他选项时才应使用宽度提示):

看起来像这样:

/----------------------------------\
| Label1                           |
| [_Text_box_1__________][Button1] |
|                                  |
| Label2                           |
| |---------------------|[Button2] |
| |  List 1             |[Button3] |
| |---------------------|          |
|                                  |
| Label3                           |
| |---------------------|[Button4] |
| |  List 2             |[Button5] |
| |---------------------|          |
|                                  |
|                 [ Ok ] [ Cancel] |
\----------------------------------/
小型:

大型:


您可以在不依赖宽度提示的情况下实现这一点(只有在没有其他选项时才应使用宽度提示):

看起来像这样:

/----------------------------------\
| Label1                           |
| [_Text_box_1__________][Button1] |
|                                  |
| Label2                           |
| |---------------------|[Button2] |
| |  List 1             |[Button3] |
| |---------------------|          |
|                                  |
| Label3                           |
| |---------------------|[Button4] |
| |  List 2             |[Button5] |
| |---------------------|          |
|                                  |
|                 [ Ok ] [ Cancel] |
\----------------------------------/
小型:

大型:


谢谢,我会试试看!有没有办法阻止文本框垂直扩展?@Alternatic
textOne.setLayoutData(新的GridData(SWT.FILL,SWT.TOP,true,false))谢谢,我会试试看!有没有办法阻止文本框垂直扩展?@Alternatic
textOne.setLayoutData(新的GridData(SWT.FILL,SWT.TOP,true,false))