界面主线程,子线程更新主界面控件
来源:互联网 发布:js获取base64文件大小 编辑:程序博客网 时间:2024/05/27 14:14
有一个主界面,然后创建 一个线程,线程更新主界面上的进度条。
效果如下所示:
代码来自http://www.java2s.com/Code/JavaAPI/org.eclipse.swt.widgets/DisplayasyncExecRunnablerun.htm
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.ProgressBar;
import org.eclipse.swt.widgets.Shell;
public class MainClass {
public static void main(String[] a) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new GridLayout());
ProgressBar pb1 = new ProgressBar(shell, SWT.HORIZONTAL | SWT.SMOOTH);
pb1.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
pb1.setMinimum(0);
pb1.setMaximum(30);
new LongRunningOperation(display, pb1).start();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
}
class LongRunningOperation extends Thread {
private Display display;
private ProgressBar progressBar;
public LongRunningOperation(Display display, ProgressBar progressBar) {
this.display = display;
this.progressBar = progressBar;
}
public void run() {
for (int i = 0; i < 30; i++) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
display.asyncExec(new Runnable() {
public void run() {
if (progressBar.isDisposed())
return;
progressBar.setSelection(progressBar.getSelection() + 1);
}
});
}
}
}
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.ProgressBar;
import org.eclipse.swt.widgets.Shell;
public class MainClass {
public static void main(String[] a) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new GridLayout());
ProgressBar pb1 = new ProgressBar(shell, SWT.HORIZONTAL | SWT.SMOOTH);
pb1.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
pb1.setMinimum(0);
pb1.setMaximum(30);
new LongRunningOperation(display, pb1).start();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
}
class LongRunningOperation extends Thread {
private Display display;
private ProgressBar progressBar;
public LongRunningOperation(Display display, ProgressBar progressBar) {
this.display = display;
this.progressBar = progressBar;
}
public void run() {
for (int i = 0; i < 30; i++) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
display.asyncExec(new Runnable() {
public void run() {
if (progressBar.isDisposed())
return;
progressBar.setSelection(progressBar.getSelection() + 1);
}
});
}
}
}
- 界面主线程,子线程更新主界面控件
- C#、Winform子线程更新界面主线程信息
- 子线程更新界面
- 多线程编程子线程访问主线程的界面
- WPF 多线程---- 子线程操作界面主线程的元素
- 在分线程更新主线程的Ui界面方法
- MFC 在线程中通过PostMessage更新界面主线程
- c#非委托方式在子线程里操作UI控件(实际上运算逻辑在子线程,更新还是在主线程,解决了UI界面无响应的问题)
- 子线程、ui界面更新
- IOS非主线程更新界面tableview
- C# 使用主线程更新winform界面
- android主线程是界面线程
- Qt子线程更新主线程方法
- javaFX 子线程更新主线程UI
- 在子线程结束后更新主界面按钮状态
- BeginInvoke的使用-1 :子线程更新主界面
- 子线程中更新ui界面
- Android 子线程 更新 UI 界面 总结
- Administrator用户直接获取SYSTEM权限
- bind9 dns智能解析 for windows 2003 master/slave dns配置
- 《Windows网络编程 2》读书笔记(一)
- Asp.Net结合JS在图层上显示记录信息
- File Dialog Example
- 界面主线程,子线程更新主界面控件
- Java基础很重要(四)---多线程
- SAPGUI中的命令行(OK-OCDE)中可敲入的命令
- 程序员到CTO必须注意的几个关键点
- UUID
- 解决:用showmodalDialog弹出aspx页面,该页面用来上传附件,点击上传如何不弹出新页面。
- 解决IE浏览器之间的兼容性问题 IE7.JS IE8.JS
- magento -- magento开发第一步-修改magento的代码实现特定的功能
- 倭寇为何一心要炸毁南开学校