I have a simple groovy script which from the main thread of execution should display some dialogs to the user.
My swing knowledge is limited and rusty, but I remember reading about the need to be careful to keep the GUI stuff in the event dispatch (EDT) stream.
If I just call the static JOptionPane.showMessageDialog method from my main thread, am I right to assume that this violates the correct practice of storing GUI files in EDT?
Should I use the swing.utils.invokeAndWait method, for example, in the following code example?
void showHelloThereDialog() throws Exception { Runnable showModalDialog = new Runnable() { public void run() { JOptionPane.showMessageDialog( myMainFrame, "Hello There"); } }; SwingUtilities.invokeAndWait (showModalDialog); }
Now the above does nothing to make values ββfrom anything other than the message dialog that is available after invokeAndWait completes.
Presumably the fact that the groovy implementation "closes" Runnable will make the code simpler than above.
Is invokeAndWait required? And if someone, please give an example of the correct implementation to get the result of something like confirmDialog with groovy?
java user-interface swing groovy event-dispatch-thread
Alex stoddard
source share