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

📄 simpleeditor1.java

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

import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ViewForm;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;

public class SimpleEditor1 {
	public static void main(String[] args) {
		final Display display = Display.getDefault();
		final Shell shell = new Shell();
		shell.setSize(327, 253);
		// ---------创建窗口中的其他界面组件-------------
		shell.setLayout(new FillLayout());

		// 用ViewForm做底层容器,并用充满型布局
		ViewForm viewForm = new ViewForm(shell, SWT.NONE);
		viewForm.setLayout(new FillLayout());

		// 在ViewForm容器里创建文本框
		final Text text = new Text(viewForm, SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
		viewForm.setContent(text);// 设置文本框为ViewForm的主组件

		// 在ViewForm容器里创建工具栏,并添加按钮事件
		ToolBar toolBar = new ToolBar(viewForm, SWT.NONE);
		ToolItem getItem = new ToolItem(toolBar, SWT.PUSH);
		getItem.setText("取得");
		getItem.setImage(new Image(display, "icons/selectall.gif"));
		getItem.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				String str = text.getText(); // 取得文本框的文字
				MessageDialog.openInformation(null, null, str);
			}
		});
		ToolItem clearItem = new ToolItem(toolBar, SWT.PUSH);
		clearItem.setText("清除");
		clearItem.setImage(new Image(display, "icons/remove.gif"));
		clearItem.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				text.setText("");// 清除文本框中的文字
			}
		});
		viewForm.setTopLeft(toolBar);// 设置工具栏在ViewForm中的位置为顶端靠左。另:此句必须放在toolBar构建完成之后
		// -----------------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 + -