File tree Expand file tree Collapse file tree
src/main/java/org/scijava/ui/swing/laf Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3535import com .formdev .flatlaf .FlatLaf ;
3636import com .formdev .flatlaf .FlatLightLaf ;
3737
38+ import java .awt .EventQueue ;
39+ import java .lang .reflect .InvocationTargetException ;
3840import java .util .Arrays ;
3941import java .util .HashMap ;
4042import java .util .Map ;
@@ -107,6 +109,25 @@ public void initLookAndFeel() {
107109 * @throws IllegalArgumentException If the given look and feel is unknown.
108110 */
109111 public void setLookAndFeel (final String lookAndFeel ) {
112+ if (!EventQueue .isDispatchThread ()) {
113+ // Note: Changing the L+F off the EDT races with Swing's own layout
114+ // and painting, which observe half-installed UI delegates and crash.
115+ try {
116+ EventQueue .invokeAndWait (() -> setLookAndFeel (lookAndFeel ));
117+ }
118+ catch (final InvocationTargetException exc ) {
119+ final Throwable cause = exc .getCause ();
120+ if (cause instanceof RuntimeException ) throw (RuntimeException ) cause ;
121+ if (cause instanceof Error ) throw (Error ) cause ;
122+ throw new RuntimeException (cause );
123+ }
124+ catch (final InterruptedException exc ) {
125+ Thread .currentThread ().interrupt ();
126+ throw new RuntimeException (exc );
127+ }
128+ return ;
129+ }
130+
110131 if (factories == null ) initFactories ();
111132
112133 if (factories .containsKey (lookAndFeel )) {
You can’t perform that action at this time.
0 commit comments