1

これは私のコードと form のスクリーンショットです。

最上部のテキスト ボックスが水平方向の空きスペースをすべて占有するようにします。
ここに画像の説明を入力

![Display display = new Display();][1]
    Shell shell = new Shell(display);
    shell.setLayout(new GridLayout());

    Group group = new Group(shell, SWT.FILL);
    group.setText("Group");
    group.setLayout(new GridLayout(4, false));
    group.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));


    Label lb = new Label(group, SWT.NONE);
    lb.setText("label");
    new Text(group, SWT.BORDER);

    Button btn = new Button(group, SWT.CHECK);
    Label lbbtn = new Label(group, SWT.NONE);
    lbbtn.setText("check");


    Composite comp = new Composite(group, SWT.NONE);
    comp.setLayout(new GridLayout(4, false));
    comp.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
    Label lb1 = new Label(comp, SWT.NONE);
    lb1.setText("Text1");
    Text txt = new Text(comp, SWT.BORDER);

    Label lb2 = new Label(comp, SWT.NONE);
    lb2.setText("Text2");
    txt = new Text(comp, SWT.BORDER);

    Label lb3 = new Label(comp, SWT.NONE);
    lb3.setText("Text3");
    txt = new Text(comp, SWT.BORDER);

    Label lb4 = new Label(comp, SWT.NONE);
    lb4.setText("Text4");
    txt = new Text(comp, SWT.BORDER);

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

1 に答える 1

4

GridDataにはwith horizontalSpanwith value 2 を使用しComposite、ウィジェットにはGridDatawith horizontalAlignmentwith valueFILLgrabExcessHorizontalSpacewith valuetrueを使用します。Text

私は通常GridDataFactoryを使用してオブジェクトを作成しGridDataます。コードはよりクリーンだと思います。

于 2012-06-10T19:07:47.127 に答える