Question

I'm trying to configure a dialog window like so:

    @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);

...

What I'm trying to accomplish is a label in the first line, that spans across both columns and have the following fields be ordered in pairs per line. What I get with this is, that the lable (that should be left in second line) is right in first line, just as the label wouldn't span across two columns. Can anybody see, what I'm doing wrong?

Thanx again!

Was it helpful?

Solution

After setting the layoutData to headlineLabel, you are setting the horizontalSpan to 1. You need to create a new LayoutData object for every SWT widget. It is not possible to reuse them after setting them.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top