Cleaned up/simplified setting the L&F for swing

This commit is contained in:
nathan 2017-02-25 23:37:50 +01:00
parent 30f3f3a3fd
commit 896744ae1e

View File

@ -45,6 +45,7 @@ import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.Locale;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
@ -123,23 +124,21 @@ class SwingUtil {
if (CUSTOM_LOOK_AND_FEEL != null && !CUSTOM_LOOK_AND_FEEL.isEmpty()) { if (CUSTOM_LOOK_AND_FEEL != null && !CUSTOM_LOOK_AND_FEEL.isEmpty()) {
// register a better looking L&F (default we use is Nimbus) // register a different L&F
String name = UIManager.getLookAndFeel().getName(); String specified = CUSTOM_LOOK_AND_FEEL.toLowerCase(Locale.US);
String current = UIManager.getLookAndFeel().getName().toLowerCase(Locale.US);
if (!CUSTOM_LOOK_AND_FEEL.equals(name)) { if (!specified.equals(current)) {
try { try {
for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) { for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
if (CUSTOM_LOOK_AND_FEEL.equals(info.getName())) { if (specified.equals(info.getName().toLowerCase(Locale.US))) {
UIManager.setLookAndFeel(info.getClassName()); UIManager.setLookAndFeel(info.getClassName());
break; break;
} }
} }
} catch (Exception e) { } catch (Exception e) {
// If Nimbus is not available, fall back to cross-platform // whoops. something isn't right!
try { e.printStackTrace();
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
} catch (Exception ignored) {
}
} }
} }
} }