Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SwingWorker blocking(?) GUI

 
George Shelp
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1101
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20492
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic