📄 progressbar1.java
字号:
package cn.com.chengang.swt;
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.ProgressBar;
import org.eclipse.swt.widgets.Shell;
public class ProgressBar1 {
public static void main(String[] args) {
final Display display = Display.getDefault();
final Shell shell = new Shell();
shell.setSize(327, 253);
// ---------创建窗口中的其他界面组件-------------
shell.setLayout(new RowLayout());
// 创建一个滑动条。这里用平滑型式样SWT.SMOOTH,默认是方格型
final ProgressBar progressBar = new ProgressBar(shell, SWT.SMOOTH);
progressBar.setMinimum(0); // 最小值
progressBar.setMaximum(100);// 最大值
// 创建一个GO按钮
Button button = new Button(shell, SWT.NONE);
button.setText("GO");
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
// 每次循环进度条前进一格,同时停顿一秒
for (int i = 1; i < 11; i++) {
progressBar.setSelection(i * 10);
try {
Thread.sleep(1000);
} catch (Throwable t) {
t.printStackTrace();
}
}
}
});
// -----------------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 + -