gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 03:18:38 25 4
gpt4 key购买 nike

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

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;

}

最佳答案

行:

pathText.setData(data);

应该是:

pathText.setLayoutData(data);

setLayoutData 不是 setData

关于java - SWT - 最后一列不会占用多余的水平空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31896173/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com