View on GitHub

Eclipse Tutorial

Ecsoya

online tutorialsWIKIoffline tutorialsPPT

FormLayout Tutorial

FormLayout是一个能控制控件的上下左右各边的位置和大小的Layout。

FormLayout

示例:

    Display display = new Display ();
    Shell shell = new Shell(display);
    FormLayout layout = new FormLayout();
    layout.marginWidth = 3;
    layout.marginHeight = 3;


    FormData data1 = new FormData();
    data1.left = new FormAttachment(0, 0);
    data1.top = new FormAttachment(0, 0);
    button1.setLayoutData(data1);
    FormData data2 = new FormData();
    data2.left = new FormAttachment(button1);
    data2.top = new FormAttachment(0, 0);
    data2.right = new FormAttachment(100, 0);
    button2.setLayoutData(data2);

FormData

示例:

    FormData data = new FormData();
    data.left = new FormAttachment(0,5);
    data.right = new FormAttachment(100,-5);
    button.setLayoutData(formData);

FormAttachment

FormAttachment有两种类型:一是基于数学比值的,二是基于其中的某一个控件(Control)的。

示例:

    FormData data = new FormData();
    data.top = new FormAttachment(0,5);
    data.bottom = new FormAttachment(100,-5);
    data.left = new FormAttachment(0,5);
    data.right = new FormAttachment(100,-5);
    button.setLayoutData(data);

参考资料

  1. FormLayout snippets
  2. SWT Example: LayoutExample

Back to Home 上一篇:GridLayout Tutorial 下一篇:StackLayout Tutorial