Results 1 to 3 of 3
- 06-17-2012, 10:12 AM #1
Displaying a JDialog from a thread other than the EDT
It's late and I can't get my head around this problem.
My application uses a worker thread that may need to display a dialog. Simple enough to queue a Runnable to be invoked by the EDT. But how can I get the user's input back from the dialog in a thread-safe way?
The simplest solution I can think of would be to use a bean with synchronized getters and setters. First the worker thread would create the bean, populate its fields, and use it to construct the dialog in the EDT. Then the dialog would update the bean when it is closed. Finally, the worker thread would retrieve the new values from the bean. The worker thread would wait() on the bean, and the dialog would notify() it.
Does anyone know a better pattern? Meanwhile, I'm going to sleep on it.Get in the habit of using standard Java naming conventions!
- 06-17-2012, 03:14 PM #2
Re: Displaying a JDialog from a thread other than the EDT
SwingPropertyChangeSupport with a PropertyChangeListener?
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 06-17-2012, 04:38 PM #3
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,606
- Rep Power
- 5
Re: Displaying a JDialog from a thread other than the EDT
Another alternative - construct a bean which contains fields for the values you need, create a final instance of this bean, then call SwingUtilities.invokeAndWait to display the dialog and populate the bean values. The thread will wait until the Swing Runnable is complete (or an Exception is thrown), after which your bean is populated with the values.
Similar Threads
-
jDialog box disappears
By pink123 in forum AWT / SwingReplies: 3Last Post: 08-19-2011, 06:07 PM -
JDialog
By Nuclear Mosquito in forum AWT / SwingReplies: 1Last Post: 07-06-2010, 03:27 PM -
JDialog
By frenk_castle in forum AWT / SwingReplies: 3Last Post: 05-11-2010, 12:28 PM -
setLocation on a JDialog is ignored
By ScottVal in forum AWT / SwingReplies: 7Last Post: 01-13-2009, 07:35 AM -
help with jdialog
By leonard in forum AWT / SwingReplies: 1Last Post: 08-05-2007, 05:37 AM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks