2015-08-08 21 views
1

我有GridLayout有4列,但无法获得最后一列(带有路径Text小部件的列)来获取多余的水平空间。SWT - 最后一列没有占用多余的水平空间

enter image description here

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

} 
+1

向我们展示版本组的所有代码 - 这可能是父复合布局之一的问题。 –

+0

'versionGroup'可能有错误的布局或错误的列数。理想情况下,它只会有'FillLayout'。 –

+0

@ greg-449:完成 – Krab

回答

2

行:

pathText.setData(data); 

应该是:

pathText.setLayoutData(data); 

setLayoutDatasetData

相关问题