Skip to content

Set the Look & Feel on the EDT #88

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 30 additions & 24 deletions src/main/java/org/scijava/ui/swing/laf/SwingLookAndFeelService.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import com.formdev.flatlaf.FlatLaf;
import com.formdev.flatlaf.FlatLightLaf;

import java.awt.EventQueue;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -112,14 +114,16 @@ public void setLookAndFeel(final String lookAndFeel) {
if (factories.containsKey(lookAndFeel)) {
// This L+F has a dedicated factory.
final LookAndFeel laf = factories.get(lookAndFeel).get();
try {
UIManager.setLookAndFeel(laf);
}
catch (final UnsupportedLookAndFeelException exc) {
attemptToRecover();
throw new IllegalArgumentException(//
"Invalid look and feel: " + lookAndFeel, exc);
}
EventQueue.invokeLater(() -> {
try {
UIManager.setLookAndFeel(laf);
}
catch (final UnsupportedLookAndFeelException exc) {
attemptToRecover();
throw new IllegalArgumentException(//
"Invalid look and feel: " + lookAndFeel, exc);
}
});
}
else {
// No dedicated factory; check for a registered L+F with a matching name.
Expand All @@ -128,23 +132,25 @@ public void setLookAndFeel(final String lookAndFeel) {
// If a L+F was found, use it; otherwise assume the argument is a class.
final String className = info == null ? lookAndFeel : info.getClassName();

try {
UIManager.setLookAndFeel(className);
}
catch (ClassNotFoundException | InstantiationException
| IllegalAccessException | UnsupportedLookAndFeelException exc)
{
attemptToRecover();
throw new IllegalArgumentException(//
"Invalid look and feel: " + lookAndFeel, exc);
}
EventQueue.invokeLater(() -> {
try {
UIManager.setLookAndFeel(className);
}
catch (ClassNotFoundException | InstantiationException
| IllegalAccessException | UnsupportedLookAndFeelException exc)
{
attemptToRecover();
throw new IllegalArgumentException(//
"Invalid look and feel: " + lookAndFeel, exc);
}

// Update all existing Swing windows to the new L+F.
FlatLaf.updateUI();

// Persist L+F setting for next time.
if (prefs != null) prefs.put(getClass(), LAF_PREF_KEY, lookAndFeel);
});
}

// Update all existing Swing windows to the new L+F.
FlatLaf.updateUI();

// Persist L+F setting for next time.
if (prefs != null) prefs.put(getClass(), LAF_PREF_KEY, lookAndFeel);
}

/**
Expand Down