FormLayout example snippet: create a simple dialog using form layout : 表单布局 « SWT « Java 教程

En
Java 教程
1. 语言基础
2. 数据类型
3. 操作符
4. 流程控制
5. 类定义
6. 开发相关
7. 反射
8. 正则表达式
9. 集合
10. 线
11. 文件
12. 泛型
13. 本土化
14. Swing
15. Swing事件
16. 二维图形
17. SWT
18. SWT 二维图形
19. 网络
20. 数据库
21. Hibernate
22. JPA
23. JSP
24. JSTL
25. Servlet
26. Web服务SOA
27. EJB3
28. Spring
29. PDF
30. 电子邮件
31. 基于J2ME
32. J2EE应用
33. XML
34. 设计模式
35. 日志
36. 安全
37. Apache工具
38. 蚂蚁编译
39. JUnit单元测试
Java
Java 教程 » SWT » 表单布局 
17. 94. 22. FormLayout example snippet: create a simple dialog using form layout
FormLayout example snippet: create a simple dialog using form layout
/*******************************************************************************
 * Copyright (c) 2000, 2004 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
//package org.eclipse.swt.snippets;
/*
 * FormLayout example snippet: create a simple dialog using form layout
 *
 * For a list of all SWT example snippets see
 * http://www.eclipse.org/swt/snippets/
 */
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;

public class DialogLayoutDemo {

  public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    Label label = new Label(shell, SWT.WRAP);
    label.setText("This is a long text string that will wrap when the dialog is resized.");
    List list = new List(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    list.setItems(new String[] { "Item 1""Item 2" });
    Button button1 = new Button(shell, SWT.PUSH);
    button1.setText("OK");
    Button button2 = new Button(shell, SWT.PUSH);
    button2.setText("Cancel");

    final int insetX = 4, insetY = 4;
    FormLayout formLayout = new FormLayout();
    formLayout.marginWidth = insetX;
    formLayout.marginHeight = insetY;
    shell.setLayout(formLayout);

    Point size = label.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    final FormData labelData = new FormData(size.x, SWT.DEFAULT);
    labelData.left = new FormAttachment(00);
    labelData.right = new FormAttachment(1000);
    label.setLayoutData(labelData);
    shell.addListener(SWT.Resize, new Listener() {
      public void handleEvent(Event e) {
        Rectangle rect = shell.getClientArea();
        labelData.width = rect.width - insetX * 2;
        shell.layout();
      }
    });

    FormData button2Data = new FormData();
    button2Data.right = new FormAttachment(100, -insetX);
    button2Data.bottom = new FormAttachment(1000);
    button2.setLayoutData(button2Data);

    FormData button1Data = new FormData();
    button1Data.right = new FormAttachment(button2, -insetX);
    button1Data.bottom = new FormAttachment(1000);
    button1.setLayoutData(button1Data);

    FormData listData = new FormData();
    listData.left = new FormAttachment(00);
    listData.right = new FormAttachment(1000);
    listData.top = new FormAttachment(label, insetY);
    listData.bottom = new FormAttachment(button2, -insetY);
    list.setLayoutData(listData);

    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch())
        display.sleep();
    }
    display.dispose();
  }
}
17. 94. 表单布局
17. 94. 1. 使用FormLayouts
17. 94. 2. FormLayout :左,右边缘
17. 94. 3. FormLayoutFormLayout
17. 94. 4. FormData对象和FormAttachment对象FormData对象和FormAttachment对象
17. 94. 5. FormData:宽度和高度FormData:宽度和高度
17. 94. 6. FormLayout:间距
17. 94. 7. 配置每一方向
17. 94. 8. Attaching a Control to a Position in the Parent CompositeAttaching a Control to a Position in the Parent Composite
17. 94. 9. Specify the offset of the control side from the attachment positionSpecify the offset of the control side from the attachment position
17. 94. 10. 没有FormAttachment对象没有FormAttachment对象
17. 94. 11. 指定附件四面控制。指定附件四面控制。
17. 94. 12. Attaching a Control to Another Control
17. 94. 13. Attaching to the Adjacent Side of Another ControlAttaching to the Adjacent Side of Another Control
17. 94. 14. Attaching to the Specified Side of Another ControlAttaching to the Specified Side of Another Control
17. 94. 15. Center a control on another controlCenter a control on another control
17. 94. 16. 中心控制横向和纵向中心控制横向和纵向
17. 94. 17. 使用FormLayout布局对话框使用FormLayout布局对话框
17. 94. 18. Start with the upper-left button, attach the top and left edges to the window, offsetting by five pixels:Start with the upper-left button, attach the top and left edges to the window,  offsetting by five pixels:
17. 94. 19. To create the upper-right three buttons, you reason that you can put them all in a composite with a grid layout, and attach the composite to your first button:To create the upper-right three buttons, you reason that you can put them all in a composite with a grid layout, and attach the composite to your first button:
17. 94. 20. Attach the bottom button to the upper-left button and the window:Attach the bottom button to the upper-left button and the window:
17. 94. 21. FormLayout复合FormLayout复合
17. 94. 22. FormLayout example snippet: create a simple dialog using form layoutFormLayout example snippet: create a simple dialog using form layout
17. 94. 23. FormLayout example snippet: center a label and single line text using a form layoutFormLayout example snippet: center a label and single line text using a form layout
17. 94. 24. FormLayout example snippet: create a simple OK/CANCEL dialog using form layoutFormLayout example snippet: create a simple OK/CANCEL dialog using form layout
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.