35
35
import com .formdev .flatlaf .FlatLaf ;
36
36
import com .formdev .flatlaf .FlatLightLaf ;
37
37
38
+ import java .awt .EventQueue ;
39
+
38
40
import java .util .Arrays ;
39
41
import java .util .HashMap ;
40
42
import java .util .Map ;
@@ -112,14 +114,16 @@ public void setLookAndFeel(final String lookAndFeel) {
112
114
if (factories .containsKey (lookAndFeel )) {
113
115
// This L+F has a dedicated factory.
114
116
final LookAndFeel laf = factories .get (lookAndFeel ).get ();
115
- try {
116
- UIManager .setLookAndFeel (laf );
117
- }
118
- catch (final UnsupportedLookAndFeelException exc ) {
119
- attemptToRecover ();
120
- throw new IllegalArgumentException (//
121
- "Invalid look and feel: " + lookAndFeel , exc );
122
- }
117
+ EventQueue .invokeLater (() -> {
118
+ try {
119
+ UIManager .setLookAndFeel (laf );
120
+ }
121
+ catch (final UnsupportedLookAndFeelException exc ) {
122
+ attemptToRecover ();
123
+ throw new IllegalArgumentException (//
124
+ "Invalid look and feel: " + lookAndFeel , exc );
125
+ }
126
+ });
123
127
}
124
128
else {
125
129
// No dedicated factory; check for a registered L+F with a matching name.
@@ -128,23 +132,25 @@ public void setLookAndFeel(final String lookAndFeel) {
128
132
// If a L+F was found, use it; otherwise assume the argument is a class.
129
133
final String className = info == null ? lookAndFeel : info .getClassName ();
130
134
131
- try {
132
- UIManager .setLookAndFeel (className );
133
- }
134
- catch (ClassNotFoundException | InstantiationException
135
- | IllegalAccessException | UnsupportedLookAndFeelException exc )
136
- {
137
- attemptToRecover ();
138
- throw new IllegalArgumentException (//
139
- "Invalid look and feel: " + lookAndFeel , exc );
140
- }
135
+ EventQueue .invokeLater (() -> {
136
+ try {
137
+ UIManager .setLookAndFeel (className );
138
+ }
139
+ catch (ClassNotFoundException | InstantiationException
140
+ | IllegalAccessException | UnsupportedLookAndFeelException exc )
141
+ {
142
+ attemptToRecover ();
143
+ throw new IllegalArgumentException (//
144
+ "Invalid look and feel: " + lookAndFeel , exc );
145
+ }
146
+
147
+ // Update all existing Swing windows to the new L+F.
148
+ FlatLaf .updateUI ();
149
+
150
+ // Persist L+F setting for next time.
151
+ if (prefs != null ) prefs .put (getClass (), LAF_PREF_KEY , lookAndFeel );
152
+ });
141
153
}
142
-
143
- // Update all existing Swing windows to the new L+F.
144
- FlatLaf .updateUI ();
145
-
146
- // Persist L+F setting for next time.
147
- if (prefs != null ) prefs .put (getClass (), LAF_PREF_KEY , lookAndFeel );
148
154
}
149
155
150
156
/**
0 commit comments