• Post Reply Bookmark Topic Watch Topic
  • New Topic

Event Dispatch Thread and the WAIT_CURSOR  RSS feed

 
Mary Taylor
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the main application is a GUI with a Menu and Menu items to choose from to do the work, can you give a general flow of events/code that will assure the WAIT_CURSOR displaying on the original GUI while the long running work is happening? Let me clarify:

1. Main GUI with Menu items is displayed
2. User chooses a Menu item to load data or sort data in a database
3. Modal dialog pops up to let the user choose a date range or enter a login, for example
4. While work is being done, it is desired the WAIT_CURSOR appear on the original GUI

I know this sounds simple, but I've been working on this off and on for way too long! I feel like I've read everything out there and worked the tutorials, etc. Java Thread Programming by Paul Hyde is an excellent book and has been helpful, but the pieces are not all together yet or the execution lacks a bit of finesse. Fancy words to say it isn't working yet!
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's a tiny bit tricky, but not too bad. The secret is to use the "glass pane" of the JFrame to block user input to the window, while still allowing the event loop to handle repaints and whatnot.

Here I'm assuming the whole thing gets kicked off in an ActionListener, and that myFrame is the main JFrame for the application.

 
Warren Dew
blacksmith
Ranch Hand
Posts: 1332
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good tip, Ernest!

A minor nit: technically, I think the workDone() call should be queued back to the dispatch thread rather than executed in the worker thread.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Warren Dew:
A minor nit: technically, I think the workDone() call should be queued back to the dispatch thread rather than executed in the worker thread.


Yes, I think you're right -- although I'm pretty sure you can get away with this without a problem.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is much easier with Spin - it requires that your long-running-thing is done in a different class, and that you have an interface for that class, but that's a good idea anyway (you automatically have that if you use the MVC pattern):



Basically, Spin.off returns a Proxy for the argument which allows to call methods on it synchronously, which will automatically be executed on a non-AWT thread without blocking the AWT thread.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!