my dog learned polymorphism*
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "SwingWorker blocking(?) GUI" Watch "SwingWorker blocking(?) GUI" New topic
Author

SwingWorker blocking(?) GUI

George Shelp
Greenhorn

Joined: Sep 30, 2012
Posts: 1
Hi,
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
Bartender

Joined: Oct 16, 2003
Posts: 1076
    
  10

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.


Ranga.
SCJP 1.4, OCMJEA/SCEA 5.0.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
wood burning stoves
 
subject: SwingWorker blocking(?) GUI
 
Similar Threads
Can any please review following piece of code
How to catch an exception from a SwingWorker
How to Pause a Countdown Timer in a GUI Without Polling
Repaint and Mouse Motion
Having problems with Window and Frame