InvokeLater does not update in time
Hi everybody,
I'm working on a small application that scans a lot of files for
information.
To let the user know what is going on, I update the following components:
- a JList containing log messages
- a JProgressBar indicating the progress in the current file
- a JProgressBar indicating global progress
The scan progress is a separate thread. I noticed that the JList was not
getting updated correctly, and after some Googling I found out that this
was because I was not updating it in the Event Dispatching Thread. So I
added the following piece of code:
--- code ---
if (SwingUtilities.isEventDispatchThread())
{
sv.showMessage(message);
}
else
{
Runnable run = new Runnable()
{
public void run()
{
sv.showMessage(message);
}
};
SwingUtilities.invokeLater(run);
}
--- /code ---
"sv" is the JFrame containing the JList. This would ensure that a) the
JList would get updated, and b) that the results would be displayed in
the EDT.
So far so good - but as a result of the amount of files, there will be
thousands and thousands of Runnables, each waiting their turn to get
executed.
The end result is a display in which both JProgressBars are both at 100%,
and the JList still is updating a list of what's going on.
How can I let the update process for the JList keep pace with the
JProgressBars?
Thanks in advance,
Ikke