?? mydialog2.java
字號:
package cn.com.chengang.jface.dialog;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.RowData;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class MyDialog2 extends Dialog {
private String textValue; // 用來保存Text值的變量
private Text text;// 將文本寫為類實例變量,否則其他方法無法訪問它
public MyDialog2(Shell parentShell) {
super(parentShell);
}
public String getTextValue() {
return this.textValue;
}
public void setTextValue(String value) {
this.textValue = value;
}
// 在這個方法里構建Dialog中的界面內容
protected Control createDialogArea(Composite parent) {
Composite topComp = new Composite(parent, SWT.NONE);
topComp.setLayout(new RowLayout());
new Label(topComp, SWT.NONE).setText("請輸入:");
text = new Text(topComp, SWT.BORDER);
// 把textValue設給Text作為初值,這時要注意對textValue作空值判斷,給文本框設置空值是會出錯的
text.setText(textValue == null ? "" : textValue);
text.setLayoutData(new RowData(100, -1));
return topComp;
}
// 單擊對話框底部按鈕會執行此方法,參數buttonId是被單擊按鈕的ID值。
protected void buttonPressed(int buttonId) {
if (buttonId == IDialogConstants.OK_ID)// 如果單擊確定按鈕,則將值保存到變量
textValue = text.getText();
super.buttonPressed(buttonId);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -