B
Ben Phillips
I started work today on a custom modal dialog class, and started to write:
SomeClass select () {
setVisible(true);
and then realized that I had no apparent way of returning the result
from the method! It has to wait for the user to interact with the dialog
and select something, so I thought of figuring out some kind of
wait/notify thing ... but then realized that hanging the EDT to wait for
the user to input something will deadlock the app.
So it looks like I need to redesign to call select from a SwingWorker
rather than from the EDT, or to have select return void and accept a
callback object.
No problem, but this caused me to think about all the places littered
through the existing code where I call the integer-returning
JOptionPane.showOptionDialog(foo...) methods ...
I suppose those need to be moved to a SwingWorker too? Since the EDT
will just sit in some event listener or another waiting for an int to be
returned from the method, while the method waits for the EDT to produce
an action event for the user clicking an option button in the dialog...
Funny that the Java Tutorial doesn't mention anything about the trio of
non-void-returning JOptionPane static methods, the EDT, and concurrency,
given that I don't see how they could be implemented not to deadlock or
else blow chunks if called on the EDT.
SomeClass select () {
setVisible(true);
and then realized that I had no apparent way of returning the result
from the method! It has to wait for the user to interact with the dialog
and select something, so I thought of figuring out some kind of
wait/notify thing ... but then realized that hanging the EDT to wait for
the user to input something will deadlock the app.
So it looks like I need to redesign to call select from a SwingWorker
rather than from the EDT, or to have select return void and accept a
callback object.
No problem, but this caused me to think about all the places littered
through the existing code where I call the integer-returning
JOptionPane.showOptionDialog(foo...) methods ...
I suppose those need to be moved to a SwingWorker too? Since the EDT
will just sit in some event listener or another waiting for an int to be
returned from the method, while the method waits for the EDT to produce
an action event for the user clicking an option button in the dialog...
Funny that the Java Tutorial doesn't mention anything about the trio of
non-void-returning JOptionPane static methods, the EDT, and concurrency,
given that I don't see how they could be implemented not to deadlock or
else blow chunks if called on the EDT.