SWT GridLayout中的horizo​​ntalSpan不跨越

时间:2012-08-26 06:57:20

标签: swt grid-layout columnspan

我正在尝试配置如下对话框窗口:

    @Override
protected Control createDialogArea(Composite parent) {


    GridLayout dialogAreaLayout = new GridLayout();
    dialogAreaLayout.numColumns = 2;
    parent.setLayout(dialogAreaLayout);


    GridData gridData = new GridData();
    gridData.grabExcessHorizontalSpace = true;
    gridData.horizontalAlignment = GridData.FILL;
    gridData.minimumWidth = 300;

    // the label in the first row should span across both columns
    gridData.horizontalSpan = 2;

    Label headlineLabel = new Label(parent, SWT.NONE);
    headlineLabel.setText("example test");
    headlineLabel.setLayoutData(gridData);

    // the rest should be ordered in two columns
    gridData.horizontalSpan = 1;

    companyLabel = new Label(parent, SWT.NONE);
    companyLabel("company");

    companyTextfield = new Text(parent, SWT.BORDER);
    companyTextfield(gridData);

...

我要完成的是第一行中的标签,跨越两列并且每行按行成对排序。我得到的是,标签(应该留在第二行)正好在第一行,就像标签不会跨越两列一样。谁能看到,我做错了什么?

再次谢谢!

1 个答案:

答案 0 :(得分:2)

将layoutData设置为headlineLabel后,您将horizo​​ntalSpan设置为1.您需要为每个SWT窗口小部件创建一个新的LayoutData对象。设置后无法重复使用它们。