2017-10-14 88 views
0

有人可以请解释两个单选按钮之间的差距的原因吗? 我甚至将水平空间设置为0,但没有任何改变。使用GridLayout的两个按钮之间的额外空格

case composed: 
new Label(container, SWT.NONE); 
new Label(container, SWT.NONE); 
new Label(container, SWT.NONE); 
container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); 
container.setLayout(new GridLayout(4, false)); 

for (int j = 0; j < this.itr; j++) { 
    Button[] radioButton = new Button[answers.size()]; 
     for (int i = 0; i < answers.size(); i++) { 
      String ans = answers.get(i).getValue(); 
      radioButton[i] = new Button(container, SWT.RADIO); 
      radioButton[i].setText(ans); 

       } 
       Text[] textField = new Text[answers.size()]; 
       for (int i = 0; i < answers.size(); i++) { 
        textField[i] = new Text(container, SWT.SINGLE | SWT.BORDER); 

      for (int i = 0; i < answers.size(); i++) { 
        textField[i] = new Text(container, SWT.SINGLE | SWT.BORDER); 
       } 
} 

我将不胜感激任何解释或解决方案。 Screenshot of the wizard

+0

也许“固定大小”字符串包含空格右边?你可以试着用'trim()'去除它们。 –

+0

我不这么认为。所有的字符串都从json文件中提取出来,并且它们具有相同的大小。 – Ben193

+0

为什么有3个'new Label(container,SWT.NONE);'在顶部?它们只是用作分隔符吗?但他们应该是4而不是3,对吗?也许第一个有不同的尺寸... –

回答

1

也许Label与文本"Please enter the key size of your algorithm"是在GridLayout的第一列,因此所有的行由它的大小的影响。

您应该划分这两个部分,例如使用不同的布局的Composites,其中一个用于第一个Label,另一个用于带按钮的内容。

例如:

container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); 
container.setLayout(new GridLayout(1, false)); 

Composite questionContainer = new Composite(container, SWT.NONE); 
questionContainer.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); 
questionContainer.setLayout(new FillLayout()); 

Label question = new Label(questionContainer, SWT.NONE); 
question.setText("Please enter the key size of your algorithm"); 

Composite contentContainer = new Composite(container, SWT.NONE); 
contentContainer.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); 
contentContainer.setLayout(new GridLayout(4, false)); 

// rest of the content using contentContainer as parent 
+0

谢谢你的回答!问题已解决 – Ben193

+1

除了额外的容器外,还可以为标签使用列宽为2的2列布局。 –