如何使用Eclipse RCP中的网格布局消除组件之间的差距?

时间:2014-10-29 12:57:14

标签: java eclipse swt jface

使用网格布局我正在创建复合材料。但我无法减少两种复合材料之间的差距。请参阅图像和代码。任何人都可以帮助我

enter image description here

parent.setLayoutData(new GridData(GridData.FILL,GridData.CENTER, true, false, 3, 1));// whole group
        GridLayout gridLayout = new GridLayout(3, false);

        recurrenceGroup.setLayout(gridLayout);

        radioButton1 = new Button(parent.getContent(), SWT.RADIO);
        radioButton1.setText("Radio 1");
        GridData gridData = GridDataFactory.fillDefaults().span(3, 1).align(SWT.FILL, SWT.BEGINNING).grab(true, false).create();
        radioButton1.setLayoutData(gridData);
        radioButton2 = new Button(parent.getContent(), SWT.RADIO);
        radioButton2.setText("Radio 2");       
        textBox = new Text(parent.getContent(), SWT.BORDER);
        textBox.setLayoutData(new GridData(SWT.BEGINING, SWT.CENTER, true, false));
        secsLabel = new Label(parent.getContent(), SWT.NONE);
        secsLabel.setText("secs");

1 个答案:

答案 0 :(得分:2)

您可以分别使用GridLayout#horizontalSpacingGridLayout#verticalSpacing来更改子项之间的间距:

水平间距:

enter image description here

没有水平间距:

enter image description here

public static void main(String[] args)
{
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("StackOverflow");

    GridLayout layout = new GridLayout(3, false);
    layout.horizontalSpacing = 0;
    shell.setLayout(layout);

    for(int i = 0; i < 9; i++)
        new Label(shell, SWT.NONE).setText("Label: " + i);

    shell.pack();
    shell.open();

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