Fix dark-mode startup failures on Linux

- Apply Swing LAF synchronously on the calling thread so the main JFrame's RootPane
  has a populated UIDefaults set when constructed.  Previously the LAF install was
  scheduled via EventQueue.invokeLater, so JFrame construction raced ahead and threw
  "no ComponentUI class for: javax.swing.JPanel".
- Call LookAndFeelFactory.installJideExtension(VSNET_STYLE) with an explicit style
  instead of the no-arg auto-detection variant.  The auto-detection path probes
  com.sun.java.swing.plaf.windows.WindowsLookAndFeel via Class.forName, which is
  absent on non-Windows JDKs and threw ClassNotFoundException at startup.
- Bounce only the SwingUtilities.updateComponentTreeUI walk through the EDT so it
  redraws already-realized windows on theme toggle.
This commit is contained in:
Akumas_Coffin_
2026-05-14 19:33:39 +10:00
parent 61f7330cd2
commit 566159198e

View File

@@ -236,35 +236,42 @@ public class ThemeManager
private void applySwingLookAndFeel(boolean darkMode)
{
Runnable r = () -> {
try
//Install the LAF synchronously on the calling thread so that any Swing components
//constructed immediately afterwards (in particular the main JFrame) find a fully
//populated UIDefaults set. UIManager.setLookAndFeel is safe to call before the EDT
//is running.
try
{
if(darkMode)
{
if(darkMode)
{
UIManager.setLookAndFeel(new FlatDarkLaf());
}
else
{
UIManager.setLookAndFeel(new FlatLightLaf());
}
UIManager.setLookAndFeel(new FlatDarkLaf());
}
catch(Exception e)
else
{
mLog.error("Unable to apply Swing look-and-feel for dark mode = " + darkMode, e);
return;
UIManager.setLookAndFeel(new FlatLightLaf());
}
}
catch(Exception e)
{
mLog.error("Unable to apply Swing look-and-feel for dark mode = " + darkMode, e);
return;
}
try
{
//JIDE components (split panes, docking) need their UI delegates re-registered
//after every LAF change.
LookAndFeelFactory.installJideExtension();
}
catch(Exception e)
{
mLog.warn("Unable to install JIDE LAF extension after theme change", e);
}
try
{
//JIDE components (split panes, docking) need their UI delegates re-registered
//after every LAF change. Pass an explicit style: the no-arg version probes
//com.sun.java.swing.plaf.windows.WindowsLookAndFeel which is not present on
//non-Windows JDKs, throwing ClassNotFoundException at startup.
LookAndFeelFactory.installJideExtension(LookAndFeelFactory.VSNET_STYLE);
}
catch(Throwable t)
{
mLog.warn("Unable to install JIDE LAF extension after theme change", t);
}
//Re-rendering any already-realized Swing windows must happen on the EDT.
Runnable updateRealized = () -> {
for(Window window: Window.getWindows())
{
SwingUtilities.updateComponentTreeUI(window);
@@ -273,11 +280,11 @@ public class ThemeManager
if(EventQueue.isDispatchThread())
{
r.run();
updateRealized.run();
}
else
{
EventQueue.invokeLater(r);
EventQueue.invokeLater(updateRealized);
}
}