您可以使用以下代码作为起点:
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();
}
它看起来像这样:
它基本上是SashForm
由两部分组成的。左边是GridLayout
三列的,右边是GridLayout
一列的。无需混合Layout
s。
百分比设置为form.setWeights(new int[] {4, 1});