Code Comments
Programming Forum and web based access to our favorite programming groups.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
Post Follow-up to this messageHal 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
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.