Reputation: 6340
I would like to accomplish the following:
Where one fixed-width control is adjacent to a horizontally-expanding control that fills the available space.
I am already able to use GridLayout
to accomplish this vertically:
by using the following code:
parent.setLayout(new GridLayout());
Button button1 = new Button(parent, SWT.PUSH);
button1.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, true, false));
button1.setText("First");
Button button2 = new Button(parent, SWT.PUSH);
button2.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
button2.setText("Second");
Is there a way to do the horizontal version without having to explicitly specify the number of columns? Other GUI toolkits (e.g. Android, QT, and GTK) do facilitate such a thing.
Currently my horizontal solution is this:
parent.setLayout(new GridLayout(2, false));
Button button1 = new Button(parent, SWT.PUSH);
button1.setLayoutData(new GridData(GridData.BEGINNING, GridData.FILL, false, true));
button1.setText("First");
Button button2 = new Button(parent, SWT.PUSH);
button2.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
button2.setText("Second");
Upvotes: 3
Views: 2641
Reputation: 19443
You have to specify the number of columns in GridLayout
. I don't understand why that should be a problem (and what you have seems to work). You can compute the number of columns as necessary depending on how many widgets you have.
This SWT Layout article is quite good. If you want to control the size of your first object, specify a widthHint
in the GridData
.
Upvotes: 4