我正在尝试使用两个文本框,一个文本框占据屏幕空间的3/4,另一个文本框占据SWT中屏幕空间的1/4。
我使用网格布局如下:
GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 1;
final Text text0 = new Text (shell, SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
final Text text1 = new Text (shell, SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
shell.setLayout(gridLayout);
text0.setLayoutData(new GridData(GridData.FILL_BOTH));
text1.setLayoutData(new GridData(GridData.FILL_HORIZONTAL,200)); //this line needs some help
目前第一个文本框占据空间的3/4,但第二个文本框不占据整个水平空间。
谢谢!
答案 0 :(得分:1)
如果您正在谈论水平空间,请使用4列网格,并使第一个文本跨越3列:
// 4 equals sized columns
shell.setLayout(new GridLayout(4, true));
final Text text0 = new Text(shell, SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
// First text spans 3 columns
text0.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1));
final Text text1 = new Text(shell, SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
// Second text is single column
text1.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
垂直划分空间要困难得多,因为使用GridData
的行跨度字段和“抓取多余空间”字段不能很好地工作。我能想到的最好的方法是使用虚拟Label
控件来获得四个等于行:
shell.setLayout(new GridLayout(2, false));
new Label(shell, SWT.LEAD).setLayoutData(new GridData(SWT.BEGINNING, SWT.FILL, false, true));
final Text text0 = new Text(shell, SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
// First text spans 3 rows
text0.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 3));
new Label(shell, SWT.LEAD).setLayoutData(new GridData(SWT.BEGINNING, SWT.FILL, false, true));
new Label(shell, SWT.LEAD).setLayoutData(new GridData(SWT.BEGINNING, SWT.FILL, false, true));
new Label(shell, SWT.LEAD).setLayoutData(new GridData(SWT.BEGINNING, SWT.FILL, false, true));
final Text text1 = new Text(shell, SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
// Second text is single row
text1.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));