I have a simple groovy script that from its main thread of execution needs to display some dialog boxes to the user.
My swing knowledge is limited and rusty but I recall reading about the need to be careful to keep GUI stuff on the event-dispatching thread (EDT).
If I just call the static JOptionPane.showMessageDialog
method from my main thread am I right in assuming this would violate the correct practice of keeping GUI stuff on the EDT?
Should I actually be using the swing.utils.invokeAndWait method such as in the following example code?
void showHelloThereDialog()
throws Exception {
Runnable showModalDialog = new
Runnable() {
public void run() {
JOptionPane.showMessageDialog(
myMainFrame, "Hello There");
}
};
SwingUtilities.invokeAndWait
(showModalDialog);
}
Now the above doesn't do anything to make values from something other than a message dialog available after invokeAndWait completes.
Presumably the fact that groovy 'closures' implement Runnable will make for simpler code than above.
Is invokeAndWait required? And if so would someone please give an example of correct implementation to get the result of something like a confirmDialog using groovy?