formattachment1.java

来自「SWTJFace篇项目源程序该项目包含 包含了Eclipse下构建swt的基本」· Java 代码 · 共 34 行

JAVA
34
字号
package cn.com.chengang.swt;

import org.eclipse.swt.SWT;
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.Shell;

public class FormAttachment1 {
	public static void main(String[] args) {
		final Display display = Display.getDefault();
		final Shell shell = new Shell();
		shell.setSize(327, 253);
		// ---------创建窗口中的其他界面组件-------------
		shell.setLayout(new FormLayout());
		Button button = new Button(shell, SWT.NONE);
		button.setText("button");
		FormData formData = new FormData();
		// 按钮的顶端(formData.top)离shell容器的空白边距是shell容器总体空白长度的60%
		formData.top = new FormAttachment(60, 0);
		button.setLayoutData(formData);
		// -----------------END------------------------
		shell.layout();
		shell.open();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		display.dispose();
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?