- 论坛徽章:
- 0
|
请问???
这涉及到 swing 和线程的关系。
你的任务(文件传送)在进行时,由于和 swing 响应事件的线程在同一个线程,程序需要等到你的任务完成后,swing 才回去响应界面事件
解决的办法是把你的任务在另一个线程里运行。
java tutorial 的例子里用的是 SwingWorker,去看看。
http://java.sun.com/docs/books/tutorial/uiswing/components/progress.html
。。。
the long-running task in this program runs in a separate thread. Generally, it's a good idea to isolate a potentially long-running task in its own thread so that the task doesn't block the rest of the program. The long-running task is implemented by LongTask.java, which uses a SwingWorker to ensure that the thread runs safely. See Using the SwingWorker Class in Threads and Swing for information about the SwingWorker class.
。。。
三个源文件:
SwingWorker.java (sun 提供)
LongTask.java
ProgressBarDemo.java |
|