Double
Double

Reputation: 11

Scheduled tasks (Timers) in Swing

A GUI using Swing, must update 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>

Upvotes: 1

Views: 466

Answers (1)

trashgod
trashgod

Reputation: 205865

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

Upvotes: 3

Related Questions