1

我想在一个包含 2 个单选按钮的复合和组中创建一个标签。但是我在对齐它时遇到了问题。它没有与标签正确对齐。该组有一个我没有使用的文本或标题。由于该文本,它没有正确对齐。但是对于复合材料,我得到了正确的行为,并且它与标签正确对齐。那么有什么方法可以使用 group.copy 来复制相同的东西。下面包含我使用的快照和代码。

代码:

shell.setLayout(new GridLayout(2,false));
GridData grid=new GridData();
Composite comp=new Composite(shell, SWT.None);

comp.setLayout(new GridLayout());
comp.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
Label label = new Label(comp, SWT.None);
label.setText("Invertframe:");

org.eclipse.swt.widgets.Group group=new org.eclipse.swt.widgets.Group(shell, SWT.None);
GridLayout layout = new GridLayout(2, true);

layout.horizontalSpacing = 0;
layout.verticalSpacing = 10;
layout.marginBottom = 0;
layout.marginHeight = 0;
layout.marginWidth = 0;

group.setLayout(layout);

group.setLayoutData(grid);
Button button =new  Button(group, SWT.RADIO);
button.setText("ON");
Button button2 =new  Button(group, SWT.RADIO);
button2.setText("OFF");
comp=new Composite(shell, SWT.None);

comp.setLayout(new GridLayout());
comp.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
label = new Label(comp, SWT.None);
label.setText("Invertframe:");

Composite composite2=new Composite(shell, SWT.BORDER);
layout = new GridLayout(2, true);
composite2.setLayout(layout);
layout.horizontalSpacing = 0;
layout.verticalSpacing = 10;
layout.marginBottom = 0;
layout.marginHeight = 0;
layout.marginWidth = 0;

button =new  Button(composite2, SWT.RADIO);
button.setText("ON");
button2 =new  Button(composite2, SWT.RADIO);
button2.setText("OFF");

在此处输入图像描述

4

2 回答 2

2

你可能没有尝试过否定verticalIndent

protected void createContents()
{
    shell.setLayout(new GridLayout(2, false));
    GridData grid = new GridData();
    grid.verticalAlignment = SWT.FILL;
    grid.verticalIndent = -6;
    Composite comp = new Composite(shell, SWT.None);

    comp.setLayout(new GridLayout());
    comp.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
    Label label = new Label(comp, SWT.None);
    label.setText("Invertframe:");

    org.eclipse.swt.widgets.Group group = new org.eclipse.swt.widgets.Group(shell, SWT.None);
    GridLayout layout = new GridLayout(2, true);

    layout.horizontalSpacing = 0;
    layout.verticalSpacing = 0;
    layout.marginBottom = 0;
    layout.marginHeight = 0;
    layout.marginWidth = 0;

    group.setLayout(layout);

    group.setLayoutData(grid);
    Button button = new Button(group, SWT.RADIO);
    GridData gd_button = new GridData(SWT.LEFT, SWT.FILL, false, false, 1, 1);
    gd_button.verticalIndent = -2;
    button.setLayoutData(gd_button);

    button.setText("ON");
    Button button2 = new Button(group, SWT.RADIO);
    GridData gd_button2 = new GridData(SWT.LEFT, SWT.FILL, false, false, 1, 1);
    gd_button2.verticalIndent = -2;
    button2.setLayoutData(gd_button2);
    button2.setText("OFF");


    comp = new Composite(shell, SWT.None);

    comp.setLayout(new GridLayout());
    comp.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
    label = new Label(comp, SWT.None);
    label.setText("Invertframe:");

    Composite composite2 = new Composite(shell, SWT.BORDER);
    layout = new GridLayout(2, true);
    composite2.setLayout(layout);
    layout.horizontalSpacing = 0;
    layout.verticalSpacing = 10;
    layout.marginBottom = 0;
    layout.marginHeight = 0;
    layout.marginWidth = 0;

    button = new Button(composite2, SWT.RADIO);
    button.setText("ON");
    button2 = new Button(composite2, SWT.RADIO);
    button2.setText("OFF");
}

与集团一致

于 2013-08-29T19:09:54.530 回答
0

嗯,你是对的。该行为是由Group的空标题字符串引起的。
我认为您无法获得所需的行为,但您可能想尝试将以下内容GridLayout应用于您的小组:

final GridLayout grid = (GridLayout) layout;
grid.horizontalSpacing = grid.marginBottom = grid.marginHeight = grid.marginLeft = grid.marginRight = grid.marginTop = grid.marginWidth = grid.verticalSpacing = 0;
于 2013-08-29T09:17:46.933 回答