Skip to content

Commit 08e86be

Browse files
authored
Merge pull request #481 from scijava/show-ui-edt
Closes imagej/imagej-legacy#306
2 parents 3074675 + 96827bf commit 08e86be

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

Diff for: src/main/java/org/scijava/ui/DefaultUIService.java

+20-4
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import java.awt.GraphicsEnvironment;
3333
import java.io.File;
3434
import java.io.FileFilter;
35+
import java.lang.reflect.InvocationTargetException;
3536
import java.util.ArrayList;
3637
import java.util.Collections;
3738
import java.util.HashMap;
@@ -161,10 +162,25 @@ public void showUI(final String name) {
161162
@Override
162163
public void showUI(final UserInterface ui) {
163164
log.debug("Launching user interface: " + ui.getClass().getName());
164-
ui.show();
165-
// NB: Also show all the current displays.
166-
for (final Display<?> display : displayService.getDisplays()) {
167-
ui.show(display);
165+
Runnable showUI = () -> {
166+
ui.show();
167+
// NB: Also show all the current displays.
168+
for (final Display<?> display : displayService.getDisplays()) {
169+
ui.show(display);
170+
}
171+
};
172+
173+
// Dispatch on EDT if necessary
174+
if (ui.requiresEDT()) {
175+
try {
176+
threadService.invoke(showUI);
177+
}
178+
catch (InterruptedException | InvocationTargetException e) {
179+
throw new RuntimeException(e);
180+
}
181+
}
182+
else {
183+
showUI.run();
168184
}
169185
eventService.publish(new UIShownEvent(ui));
170186
}

0 commit comments

Comments
 (0)