开发者

Scheduled tasks (Timers) in Swing

开发者 https://www.devze.com 2023-02-01 04:28 出处:网络
A GUI using Swing, must updat开发者_开发问答e part of its UI from a every 5 seconds. (output.setPage(url))

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().

0

精彩评论

暂无评论...
验证码 换一张
取 消