Reputation: 975
I am trying to have two textboxes, one textbox to occupy 3/4th of the screen space and the other textbox to occupy 1/4th of the screen space in SWT.
I am using grid layout as follows:
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
Currently the first text box occupies the 3/4 of the space, but the second text box doesn't fill the entire horizontal space.
Thanks!
Upvotes: 1
Views: 430
Reputation: 111142
If you are talking about horizontal space use a 4 column grid and make the first text span 3 columns:
// 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));
Dividing up the space vertically is much more tricky as using the row span field of GridData
with the 'grab excess space' field doesn't work very well. The best I can come up with uses dummy Label
controls to get four equals rows:
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));
Upvotes: 1