ProgressBar using Threads in SWT

馋奶兔 提交于 2019-12-13 17:31:09

问题


In my SWT Application i wish to use a progress bar (org.eclipse.swt.widgets.ProgressBar) i found examples but could not understand the proper flow and usage i need to perform background task for which, i was paused at the algorithm phase like i can analyze that there should be two threads one for background job, another for a progressbar both should execute simultaneously, i could not figure out the Implementation of this,i found plenty of examples but,i was puzzled where should i place my background task code (still searching). Can anyone provide sample example that suits me.


回答1:


Did you see update a progress bar (from another thread) from SWT ProgressBar snippets page? It explains a lot.

ProgressBar have to be asynchronous to work correctly in every GUI framework. It's job is to show some value independently on main (GUI) thread. So you have to write your own thread, which will maintain the ProgressBar, resolving current value of it and show the changes of value (rendering progress by widget itself).

In Swing, you don't have to create you own thread for ProgressBar, because the class already implements upper proposed behavior (makes itself another thread and manage the work for you). But because SWT is platform dependent (and for other reasons), you have to manage this by yourself.



来源:https://stackoverflow.com/questions/7293903/progressbar-using-threads-in-swt

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!