I have an RCP/SWT application in which I\'m trying to construct a view out of existing composites. One is a FillLayout composite, the other uses GridLayout.
I\'d to like
You can use the following code as a starting point:
public static void main(String[] args)
{
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new GridLayout(1, false));
SashForm form = new SashForm(shell, SWT.HORIZONTAL);
form.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
Composite left = new Composite(form, SWT.BORDER);
left.setLayout(new GridLayout(3, true));
left.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
for(int i = 0; i < 9; i++)
{
Button button = new Button(left, SWT.PUSH);
button.setText("Button " + i);
button.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true));
}
final Composite right = new Composite(form, SWT.BORDER);
right.setLayout(new GridLayout(1, true));
right.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
Button fillButton = new Button(right, SWT.PUSH);
fillButton.setText("Fill");
fillButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
/* Set the width to 80% and 20% */
form.setWeights(new int[] {4, 1});
shell.setSize(400, 400);
shell.open();
while (!shell.isDisposed())
{
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
It looks like this:
It's basically a SashForm
with two parts. The left part is a GridLayout
with three columns and the right part is a GridLayout
with one column. No need to mix Layout
s.
The percentage is set with form.setWeights(new int[] {4, 1});