SWT:充满式布局

来源:互联网 发布:大数据平台性能指标 编辑:程序博客网 时间:2024/05/19 16:23

public static void showFillStyle(Shell shell) {
  // 两种定位方式
  // 绝对定位
  // button.setBounds(30, 20, 100, 50);
  // 托管定位
  // shell.setLayout(Layout layout);
  // 常见的布局管理器
  // FillLayout(充满式布局)
  // RowLayout(行列式布局)
  // GridLayout(网格式布局)
  // FormLayout(表格式布局)
  // StackLayout(堆栈式布局)
  FillLayout layout = new FillLayout();
  // 定义水平填充
  layout.type = SWT.HORIZONTAL;
  // 定义垂直填充
  // layout.type = SWT.VERTICAL;
  // 设置四周补白
  layout.marginHeight = 10; // 设置上下补白高度
  layout.marginWidth = 20; // 设置左右补白
  layout.spacing = 5; // 设置控件之间的空隙
  shell.setLayout(layout);

  new Button(shell, SWT.NONE).setText("B1");
  new Button(shell, SWT.NONE).setText("Button2");
  new Button(shell, SWT.NONE).setText("B3");

  shell.layout();
  shell.pack();
  shell.open();
 }