File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes SwingWorker blocking(?) GUI Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "SwingWorker blocking(?) GUI" Watch "SwingWorker blocking(?) GUI" New topic

SwingWorker blocking(?) GUI

George Shelp

Joined: Sep 30, 2012
Posts: 1
I have this problem I've had for a few days and I really don't understand why my gui calls get blocked.

I have a program where I have a SwingWorker run a timer in doInBackground and I simultaneously listen for user input with mouselistener on mousepressed event. Then I cancel the timer thread if done in a certain interval and get the time at which it was stopped back and try to update the GUI whether it was a hit or a miss (I display image and play a sound in startinteraction). If there is no input, timer runs out and then starts up after an interval. Can someone please tell me why GUI updates are blocked ? Specifically, last few milliseconds of the timer aren't showing when it's stopped (ie if interval is 1.500 seconds it stops at 1.467 or so) and the update "hit" or "miss" isn't shown until the next thread is ran.
I have wrapped the calls to update functions in runnable, and all but there are still no simultaneous label updates, even though I know the execution path and parameters are all passed correctly. All gui updates are ran in the EDT thread as far as I can tell. Please help !

Here's the relevant code:

Ranganathan Kaliyur Mannar

Joined: Oct 16, 2003
Posts: 1101

Hi George,
Welcome to the Ranch!

You have used SwingWorker for the task and also made the publish() call to process intermediate results. This in turn calls process() method. So, in the process method, there is no need to use SwingUtilities. You can directly update the GUI in the process() method.
You can go through this example from the tutorial to understand more on this.

Rob Spoor

Joined: Oct 27, 2005
Posts: 20271

You're calling stopAndStart() from the done() method, so it's called on the EDT. That means you're sleeping on the EDT. You shouldn't do that.
I'm also not sure if clipLoop.get(soundcount) (which you call twice) will be short enough to run in the EDT, it probably isn't.

How To Ask Questions How To Answer Questions
I agree. Here's the link:
subject: SwingWorker blocking(?) GUI
jQuery in Action, 3rd edition