Home > Archive > Java Help > September 2004 > Updating Swing Display Regulary in Background
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Updating Swing Display Regulary in Background
|
|
| Hal Vaughan 2004-09-21, 3:59 pm |
| I think this would be setup with Thread, but I'm posting it with the idea
that there might be a better way, or something I'm unaware of that might
work better.
I have a Swing app that creates a number of files in a directory and later
prints them out. In the app window, I want to be able to keep an updated
count of how many files are in the directory, waiting to be printed. The
best way I know of to do this is to use Thread and create a small thread
that is essentially a While loop. Inside the loop, I count the files in
the directory, then sleep for a few seconds, then repeat. I'd start this
thread once the GUI is complete and visible.
Is this pretty much the "best" way (recognizing that "best" is a relative
term) to do this, or are there other ways that are recommended?
Thanks!
Hal
| |
| Eric Sosman 2004-09-21, 3:59 pm |
| Hal Vaughan wrote:
> I think this would be setup with Thread, but I'm posting it with the idea
> that there might be a better way, or something I'm unaware of that might
> work better.
>
> I have a Swing app that creates a number of files in a directory and later
> prints them out. In the app window, I want to be able to keep an updated
> count of how many files are in the directory, waiting to be printed. The
> best way I know of to do this is to use Thread and create a small thread
> that is essentially a While loop. Inside the loop, I count the files in
> the directory, then sleep for a few seconds, then repeat. I'd start this
> thread once the GUI is complete and visible.
>
> Is this pretty much the "best" way (recognizing that "best" is a relative
> term) to do this, or are there other ways that are recommended?
It's probably better to have your "working" thread
update the GUI each time it finishes a file, using
SwingUtilities.invokeLater().
--
Eric.Sosman@sun.com
|
|
|
|
|