Scheduled tasks (Timers) in Swing
A GUI using Swing, must updat开发者_开发问答e part of its UI from a every 5 seconds. (output.setPage(url)
)
The code is running in a timer, but on every update, the GUI hangs.
How do I avoid making the UI hang?
Here is my code:
<insert code here>
Assuming you are using a setPage()
method of JEditorPane
, the event dispatch thread is blocked while the page is fetched. Using SwingWorker
is a reasonable alternative.
Addendum: SwingWorker
is convenient for showing progress; but as an alternative, you might look into the asynchronous feature of setPage()
using setAsynchronousLoadPriority()
.
精彩评论