• Post Reply Bookmark Topic Watch Topic
  • New Topic

Unfreezing a GUI while a process it running  RSS feed

 
Jamie Vaugh
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any way I can unfreeze my GUI while a process is running, for example if i run a process which takes 5 minutes, the Jframe will be frozen and unable to press buttons etc.. untill the main process is running. I'll appriciate every bit of help, thank you.

P.S I'm trying to make it unfeeze so a progress bar can work.
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use a background thread such as a SwingWorker here and you'll unfreeze your GUI.

Your problem is that you're running your long process on the Event Dispatch Thread or EDT. This is the single thread that is used by Swing to paint the app and to interact with the user (accept keyboard and mouse input, etc...). When you tie this up you tie up the entire app as Swing can no longer paint or interact. The key is to do long-running processes in the background, but to interact with Swing only via the EDT so you don't put Swing into a dead lock or other bad concurrency situation. The SwingWorker class, part of Java 1.6 was built to try to simplify the solution to this problem by giving you a place for your background processes, a place for this process to publish its results to Swing and a place for it to announce that it is through. I highly recommend you start reading here: Concurrency in Swing
 
Jamie Vaugh
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've seen the
but never really understood the concept of it.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the tutorial might be a good starting point

http://java.sun.com/docs/books/tutorial/uiswing/concurrency/worker.html

have a go, and if you get stuck, post what you've tried.
 
Campbell Ritchie
Sheriff
Posts: 53779
128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to JavaRanch
 
Jamie Vaugh
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah thanks a lot, seems like a great place for help/support
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!