?? simpleeditor1.java
字號:
/**
* @作者:陳剛
* @Email:glchengang@yeah.net
* @Blog:http://blog.csdn.net/glchengang
*/
package 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.setText("SWT Application");
//------------------新插入的界面核心代碼------------------------
shell.setLayout(new FillLayout());
//用ViewForm做底層容器,并用充滿型布局
ViewForm viewForm = new ViewForm(shell, SWT.NONE);
viewForm.setLayout(new FillLayout());
//在ViewForm上建立工具欄和文本框
ToolBar toolBar = new ToolBar(viewForm, SWT.NONE);
final Text text = new Text(viewForm, SWT.BORDER | SWT.V_SCROLL);
//設置工具欄和文本框在ViewForm上的位置
viewForm.setContent(text);
viewForm.setTopLeft(toolBar);
/*
* 為工具欄添加按鈕及相應事件
*/
ToolItem toolItem = new ToolItem(toolBar, SWT.PUSH);
toolItem.setText("取得");
//按鈕圖片
toolItem.setImage(new Image(display, "icons/selectAll.gif"));
toolItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
String str = text.getText(); //取得文本框的文字
MessageDialog.openInformation(null, null, str);
}
});
ToolItem toolItem2 = new ToolItem(toolBar, SWT.PUSH);
toolItem2.setText("清除");
toolItem2.setImage(new Image(display, "icons/remove.gif"));
toolItem2.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
text.setText("");//清除文本框中的文字
}
});
//------------------END---------------------------------------------
shell.layout();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -