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

📄 swtinform.java

📁 SWTJFace篇项目源程序该项目包含 包含了Eclipse下构建swt的基本工程
💻 JAVA
字号:
package cn.com.chengang.form;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.ui.forms.widgets.FormToolkit;

public class SwtInForm {
	public static void main(String[] args) {
		final Display display = Display.getDefault();
		final Shell shell = new Shell();
		shell.setSize(400, 300);
		// ---------创建窗口中的其他界面组件-------------
		shell.setLayout(new RowLayout());
		{// 用普通的new方式创建的SWT组件
			Composite comp = new Composite(shell, SWT.NONE);
			comp.setLayout(new RowLayout());
			new Label(comp, SWT.NONE).setText("姓名");
			new Label(comp, SWT.SEPARATOR).setText("姓名");
			new Text(comp, SWT.BORDER).setText("陈刚");
			new Button(comp, SWT.PUSH).setText("确定");
			new Button(comp, SWT.CHECK).setText("读书");
			new Table(comp, SWT.NONE);
			new Tree(comp, SWT.NONE);
		}
		{// 用FormToolkit的create方法创建SWT组件
			FormToolkit toolkit = new FormToolkit(display);
			Composite comp = toolkit.createComposite(shell);
			comp.setLayout(new RowLayout());
			toolkit.createLabel(comp, "姓名");
			toolkit.createSeparator(comp, SWT.NONE);
			toolkit.createText(comp, "陈刚");
			toolkit.createButton(comp, "确定", SWT.PUSH);
			toolkit.createButton(comp, "读书", SWT.CHECK);
			toolkit.createTable(comp, SWT.NONE);
			toolkit.createTree(comp, SWT.NONE);
		}
		{// 用FormToolkit的create方法创建SWT组件
			FormToolkit toolkit = new FormToolkit(display);
			Composite comp = toolkit.createComposite(shell);
			comp.setLayout(new RowLayout());
			toolkit.createLabel(comp, "姓名");
			toolkit.createSeparator(comp, SWT.NONE);
			toolkit.createText(comp, "陈刚");
			toolkit.createButton(comp, "确定", SWT.PUSH);
			toolkit.createButton(comp, "读书", SWT.CHECK);
			toolkit.createTable(comp, SWT.NONE);
			toolkit.createTree(comp, SWT.NONE);
			toolkit.paintBordersFor(comp);// 将copm中的组件以平面边框式样描绘
		}

		// -----------------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 + -