我有4列的GridLayout,但是无法获取最后一列(具有路径Text小部件的列)来获取多余的水平空间。

java - SWT-最后一列不会占用过多的水平空间-LMLPHP

    @Override
    protected Control createDialogArea(Composite parent) {

    Composite composite = (Composite) super.createDialogArea(parent);

    ((GridLayout)composite.getLayout()).numColumns = 2;


    Label label = null;
    GridData data = null;
    Composite compo = null;
    Composite compo2 = null;
    GridLayout layout = null;

    // accounts label
    label = new Label(composite, SWT.LEFT);
    label.setText("Accounts");

    data = new GridData();
    data.horizontalSpan = 2;
    label.setLayoutData(data);

    //accounts combo
    ComboViewer accountsCombo = new ComboViewer(composite);
    accountsCombo.getCombo().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

    //accounts add button
    Button btnAddAccount = new Button(composite, SWT.PUSH);
    btnAddAccount.setText(BUTTON_ADD_ACC_LABEL);
    btnAddAccount.setLayoutData(new GridData());

    // repo-package composite
    compo = new Composite(composite, SWT.NONE);
    data = new GridData(SWT.FILL, SWT.FILL, true, false);
    data.horizontalSpan = 2;
    compo.setLayoutData(data);
    layout = new GridLayout();
    layout.marginWidth = 0;
    layout.numColumns = 2;
    compo.setLayout(layout);

    //repo composite
    compo2 = new Composite(compo, SWT.NONE);
    data = new GridData(SWT.FILL, SWT.FILL, true, false);
    compo2.setLayoutData(data);
    layout = new GridLayout();
    layout.marginWidth = 0;
    compo2.setLayout(layout);

    //repo label
    Label repoLabel = new Label(compo2, SWT.LEFT);
    repoLabel.setText("Repository");

    //repo combo
    ComboViewer repoCombo = new ComboViewer(compo2);
    repoCombo.getCombo().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

    //package composite
    compo2 = new Composite(compo, SWT.NONE);
    compo2.setLayoutData(data);
    layout = new GridLayout();
    layout.marginWidth = 0;
    compo2.setLayout(layout);

    //package label
    label = new Label(compo2, SWT.LEFT);
    label.setText("Package");

    //package combo
    ComboViewer packageCombo = new ComboViewer(compo2);
    packageCombo.getCombo().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

    // version group
    Group versionGroup = new Group(composite, SWT.NONE);
    versionGroup.setText("Version");
    data = new GridData(SWT.FILL, SWT.FILL, true, false);
    data.horizontalSpan = 2;
    versionGroup.setLayoutData(data);
    layout = new GridLayout();
    versionGroup.setLayout(layout);

    // replace radio
    Button radioReplaceVersion = new Button(versionGroup, SWT.RADIO);
    radioReplaceVersion.setText("replace");
    radioReplaceVersion.setSelection(true);

    // replace composite
    compo = new Composite(versionGroup, SWT.NONE);
    data = new GridData(SWT.FILL, SWT.FILL, true, false);
    layout = new GridLayout();
    layout.numColumns = 4;
    compo.setLayoutData(data);
    compo.setLayout(layout);

    // name label
    label = new Label(compo, SWT.LEFT);
    label.setText("name:");
    data = new GridData(SWT.LEFT, SWT.CENTER, false, false);
    label.setLayoutData(data);

    // name text widget
    Text nameText = new Text(compo, SWT.SINGLE | SWT.BORDER);
    data = new GridData(SWT.FILL, SWT.FILL, false, false);
    data.widthHint = 150;
    nameText.setLayoutData(data);

    // path label
    label = new Label(compo, SWT.LEFT);
    label.setText("path:");
    data = new GridData(SWT.LEFT, SWT.CENTER, false, false);
    label.setLayoutData(data);

    // path text widget
    Text pathText = new Text(compo, SWT.SINGLE | SWT.BORDER);
    data = new GridData(SWT.FILL, SWT.FILL, true, false);
    pathText.setData(data);

    /*
    for (Control cnt : compo.getChildren()) {
        cnt.setEnabled(false);
    }
    */
    // new radio
    Button radioNewVersion = new Button(versionGroup, SWT.RADIO);
    radioNewVersion.setText("new");


    //resource label
    label = new Label(composite, SWT.LEFT);
    label.setText("Resources");
    data = new GridData();
    data.horizontalSpan = 2;
    label.setLayoutData(data);

    // resource composite
    compo = new Composite(composite, SWT.NONE);
    compo.setLayout(new GridLayout());
    data = new GridData(SWT.FILL, SWT.FILL, true, true);
    data.horizontalSpan = 2;
    compo.setLayoutData(data);

    // resource widget
    createResourcesGroup(compo);

    return parent;

}

最佳答案

该行:

pathText.setData(data);


应该:

pathText.setLayoutData(data);


setLayoutData不是setData

08-17 02:25