?? progressmonitordialog1.java
字號:
package cn.com.chengang.jface.dialog;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class ProgressMonitorDialog1 {
public static void main(String[] args) {
new ProgressMonitorDialog1().open();
}
public void open() {
final Display display = Display.getDefault();
final Shell shell = new Shell();
shell.setSize(500, 375);
shell.setLayout(new RowLayout());
Button button = new Button(shell, SWT.NONE);
button.setText(" GO ");
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
// 創建進度條對話框的處理過程對象
IRunnableWithProgress runnable = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) {
monitor.beginTask("開始執行......", 10);
for (int i = 0; i < 10; i++) {// 循環10次,每次間隔一秒
if (monitor.isCanceled()) // 隨時監控是否選擇了對話框的“取消”按鈕
return;// 中斷處理
try {
Thread.sleep(1000);
} catch (Throwable t) {}
monitor.setTaskName("第" + (i + 1) + "次循環");// 提示信息
monitor.worked(1);// 進度條前進一步
}
monitor.done();// 進度條前進到完成
}
};
try {
// 創建一個進度條對話框,并將runnable傳入
// 第一個參數推薦設為true,如果設為false則處理程序會運行在UI線程里,界面將有一點停滯感。
// 第二個參數:true=對話框的“取消”按鈕有效
new ProgressMonitorDialog(shell).run(true, true, runnable);
} catch (Exception e2) {
e2.printStackTrace();
}
}
});
shell.layout();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -