This week's book giveaway is in the OCAJP forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line! See this thread for details.
Hi, I'm using a JFrame containing a JTextarea.I'm displaying the list of files in the specified folder (i.e. appending it to the jtextarea).When the system is processing it does not display the updated containers.Moreover if we switch to some other application & return to it,the jframe is fully blank until the files are completely found.I want to add to the list whenever each file is found & stop it intermediately.Please reply me as soon as possible. Happy middling with java. Bye from Netharam.
It sounds like you are executing a long process on the same thread that is used to refresh the GUI components in your application. Essentially what you need to do is spawn a new thread to do your file processing for you. This way, the GUI thread is free to perform whatever updates (repaints) that it needs to do without having to wait for your processing to finish. Spawning a new thread will make it easy for you to also update the data in your components while the processing is happening. For example, if you receive a file name from your process, you can append that to the JTextArea and it will be displayed WHILE your process is off getting the next file name. You can also stop your processing by pressing a button or otherwise interacting with the GUI if you use a thread. Hope this helps!
Jeff Wisard<br />Sun Certified Java Programmer (Java 2)<br />Sun Certified Web Component Developer
Hi, If you search for "Swing Worker" on the sun site you'll find a very handy implementation of background threads specially designed for swing by people at Sun. I had similar problems with a data access interface and this worked a treat - and it was easy to drop into event methods too Hope that helps,