0
當我添加兩個Text控件(dUsername和dPassword)時,它們沒有正確對齊。請參閱附加的屏幕截圖。 添加到組合旁邊的兩個Text控件應放置在它們各自的標籤標題下。但是,我無法找到不正確對齊的原因。如果我能得到任何關於相同的指示,這將是非常有幫助的。SWT文本在網格佈局中未正確對齊
public void createControl(Composite Parent) {
Composite container = new Composite(Parent, SWT.NULL);
GridLayout layout = new GridLayout();
container.setLayout(layout);
layout.numColumns = 10;
layout.verticalSpacing = 20;
layout.horizontalSpacing = 15;
GridData gd1 = new GridData(GridData.BEGINNING, GridData.BEGINNING, false, false, 1, 1);
createLabelSection(container,gd1);
getARowForEach(container,gd1);
}
private void getARowForEach(Composite container, GridData grid) {
while (some condition) {
String dString = (String) dIterator.next();
addControls(dString, container, grid);
}
}
private void addControls(String dvString, Composite container, GridData grid) {
Button checkBox = setCheckBoxText(container, null);
String dvLabel = dvString;
getLabelCaption(container,dvLabel);
Combo hostCombo = setComboText(container);
Text dUsername = new Text(container, SWT.NONE);
Text dPassword = new Text(container, SWT.PASSWORD);
}
public Button setCheckBoxText(Composite container, Label label){
Button checkBox = new Button(container, SWT.CHECK);
GridData gd = new GridData(GridData.FILL, GridData.CENTER, true, false, 2, 1);
checkBox.setLayoutData(gd);
checkBox.setSelection(true);
return checkBox;
}
public Label getLabelCaption(Composite container, String caption){
Label label = new Label(container, SWT.NONE);
GridData grid = new GridData(SWT.LEFT, SWT.TOP, false, false, 1, 1);
label.setLayoutData(grid);
label.setText(caption);
return label;
}
public Combo setComboText(Composite container){
Combo combo = new Combo(container, SWT.READ_ONLY);
GridData gd = new GridData(GridData.FILL, GridData.CENTER, true, false, 2, 1);
combo.setLayoutData(gd);
.
.
combo.select(0);
return combo;
}
private void createLabelSection(Composite container,GridData grid) {
addLabel(container, grid, "some details");
addLabel(container, grid, "some details");
addLabel(container, grid, "some details");
addLabel(container, grid,"username");
addLabel(container, grid, "password");
}
文本dashUsername =新文本(容器,SWT.NONE); dashUsername.setLayoutData(new GridData(SWT.FILL,SWT.BEGINNING,false,false,2,1)); \t \t \t \t Text dashPassword = new Text(container,SWT.PASSWORD); dashPassword.setLayoutData(new GridData(SWT.FILL,SWT.BEGINNING,false,false,2,1)); – user3594891 2014-12-03 10:02:59
我試過這個,發現文本與現有代碼正確對齊。感謝GGrec的幫助。 – user3594891 2014-12-03 10:06:02