⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 formattachment2.java

📁 SWTJFace篇项目源程序该项目包含 包含了Eclipse下构建swt的基本工程
💻 JAVA
字号:
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;
import org.eclipse.swt.widgets.Text;

public class FormAttachment2 {
	public static void main(String[] args) {
		final Display display = Display.getDefault();
		final Shell shell = new Shell();
		shell.setSize(327, 253);
		// ---------创建窗口中的其他界面组件-------------
		shell.setLayout(new FormLayout());
		Text text1 = new Text(shell, SWT.BORDER);
		text1.setLayoutData(new FormData(100, 50));
		// 定义并设置FormData
		FormData formData = new FormData();
		// 以text1为基准偏移50像素
		FormAttachment formAttachment = new FormAttachment(text1, 50);
		// FormAttachment formAttachment = new FormAttachment(text1, 50,
		// SWT.LEFT);参数3的可选值包括SWT.DEFAULT、SWT.LEFT、SWT.CENTER、SWT.RIGHT、SWT.TOP、SWT.BOTTOM
		formData.top = formAttachment;
		formData.left = formAttachment;
		// 将button1应用FormData
		Button button1 = new Button(shell, SWT.NONE);
		button1.setText("button1");
		button1.setLayoutData(formData);
		// -----------------END------------------------
		shell.layout();
		shell.open();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		display.dispose();
	}
}

⌨️ 快捷键说明

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