單列
在此示例中,我們使用預設的 no-args GridLayout()
建構函式來建立具有單個列的佈局。
public class SingleColumnGridLayoutExample {
private final Display display;
private final Shell shell;
public SingleColumnGridLayoutExample() {
display = new Display();
shell = new Shell(display);
// Create the layout and apply to the Shell
shell.setLayout(new GridLayout());
// Add the child controls to the Shell - in this case, in a single column
final Button buttonA = new Button(shell, SWT.PUSH);
buttonA.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
buttonA.setText("Button A");
final Button buttonB = new Button(shell, SWT.PUSH);
buttonB.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
buttonB.setText("Button B");
final Button buttonC = new Button(shell, SWT.PUSH);
buttonC.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
buttonC.setText("Button C");
final Button buttonD = new Button(shell, SWT.PUSH);
buttonD.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
buttonD.setText("Button D");
}
public void run() {
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
public static void main(final String... args) {
new SingleColumnGridLayoutExample().run();
}
}
結果是: