diff options
author | Juergen Schmidt <jsc@openoffice.org> | 2011-02-23 14:27:55 +0100 |
---|---|---|
committer | Juergen Schmidt <jsc@openoffice.org> | 2011-02-23 14:27:55 +0100 |
commit | 6a500920e5e34fc2ed5cd94e7d0b725f0d58b27b (patch) | |
tree | 4423abc20999c891ae6c700ad1e4ffd291921544 /odk/examples | |
parent | 4ef76a17eed2c60b361961c9c31326ccb164512e (diff) |
jsc340: fix problem with showing Java awt UI from the AppKit thread
Diffstat (limited to 'odk/examples')
-rw-r--r-- | odk/examples/DevelopersGuide/Components/Addons/JobsAddon/AsyncJob.java | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/odk/examples/DevelopersGuide/Components/Addons/JobsAddon/AsyncJob.java b/odk/examples/DevelopersGuide/Components/Addons/JobsAddon/AsyncJob.java index 4a4733c674ed..790a52d46fb1 100644 --- a/odk/examples/DevelopersGuide/Components/Addons/JobsAddon/AsyncJob.java +++ b/odk/examples/DevelopersGuide/Components/Addons/JobsAddon/AsyncJob.java @@ -312,7 +312,22 @@ public class AsyncJob extends WeakBase implements XServiceInfo, XAsyncJob // Because we need a parent anytime. // And showing e.g. a java dialog can make some trouble // inside office ... but we have no chance here. - javax.swing.JOptionPane.showMessageDialog(null, sMessage, sTitle, javax.swing.JOptionPane.INFORMATION_MESSAGE); + final java.lang.String sFinalTitle = sTitle; + final java.lang.String sFinalMessage = sMessage; + + // On Mac OS X, AWT/Swing must not be accessed from the AppKit thread, so call + // SwingUtilities.invokeLater always on a fresh thread to avoid that problem + // (also, the current thread must not wait for that fresh thread to terminate, + // as that would cause a deadlock if this thread is the AppKit thread): + final Runnable doRun = new Runnable() { + public void run() { + javax.swing.JOptionPane.showMessageDialog(null, sFinalMessage, sFinalTitle, javax.swing.JOptionPane.INFORMATION_MESSAGE); + } + }; + + new Thread( doRun ) { + public void run() { javax.swing.SwingUtilities.invokeLater(doRun); } + }.start(); } //___________________________________________ |