4545import javax .swing .UIManager .LookAndFeelInfo ;
4646import javax .swing .UnsupportedLookAndFeelException ;
4747
48+ import org .scijava .log .LogService ;
4849import org .scijava .plugin .Parameter ;
4950import org .scijava .plugin .Plugin ;
5051import org .scijava .prefs .PrefService ;
@@ -68,6 +69,9 @@ public class SwingLookAndFeelService extends AbstractService implements
6869 @ Parameter (required = false )
6970 private PrefService prefs ;
7071
72+ @ Parameter (required = false )
73+ private LogService log ;
74+
7175 /** Mapping from look-and-feel name to an associated factory. */
7276 private Map <String , Supplier <LookAndFeel >> factories ;
7377
@@ -80,9 +84,19 @@ public class SwingLookAndFeelService extends AbstractService implements
8084 */
8185 public void initLookAndFeel () {
8286 // Set the L+F to match the user setting, or "FlatLaf Light" initially.
83- final String laf = prefs == null ? null : //
87+ final String lafPref = prefs == null ? null : //
8488 prefs .get (getClass (), LAF_PREF_KEY );
85- setLookAndFeel (laf == null ? FlatLightLaf .NAME : laf );
89+ final String laf = lafPref == null ? FlatLightLaf .NAME : lafPref ;
90+ try {
91+ setLookAndFeel (laf );
92+ }
93+ catch (final IllegalArgumentException exc ) {
94+ // If something goes wrong, no worries -- just log the exception.
95+ if (log != null ) {
96+ log .warn ("Could not set Look & Feel '" + laf + "'" );
97+ log .debug (exc );
98+ }
99+ }
86100 }
87101
88102 /**
0 commit comments