mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-16 18:47:33 -05:00
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:
@@ -236,35 +236,42 @@ public class ThemeManager
|
|||||||
|
|
||||||
private void applySwingLookAndFeel(boolean darkMode)
|
private void applySwingLookAndFeel(boolean darkMode)
|
||||||
{
|
{
|
||||||
Runnable r = () -> {
|
//Install the LAF synchronously on the calling thread so that any Swing components
|
||||||
try
|
//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());
|
||||||
{
|
|
||||||
UIManager.setLookAndFeel(new FlatDarkLaf());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
UIManager.setLookAndFeel(new FlatLightLaf());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch(Exception e)
|
else
|
||||||
{
|
{
|
||||||
mLog.error("Unable to apply Swing look-and-feel for dark mode = " + darkMode, e);
|
UIManager.setLookAndFeel(new FlatLightLaf());
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
mLog.error("Unable to apply Swing look-and-feel for dark mode = " + darkMode, e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
//JIDE components (split panes, docking) need their UI delegates re-registered
|
//JIDE components (split panes, docking) need their UI delegates re-registered
|
||||||
//after every LAF change.
|
//after every LAF change. Pass an explicit style: the no-arg version probes
|
||||||
LookAndFeelFactory.installJideExtension();
|
//com.sun.java.swing.plaf.windows.WindowsLookAndFeel which is not present on
|
||||||
}
|
//non-Windows JDKs, throwing ClassNotFoundException at startup.
|
||||||
catch(Exception e)
|
LookAndFeelFactory.installJideExtension(LookAndFeelFactory.VSNET_STYLE);
|
||||||
{
|
}
|
||||||
mLog.warn("Unable to install JIDE LAF extension after theme change", e);
|
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())
|
for(Window window: Window.getWindows())
|
||||||
{
|
{
|
||||||
SwingUtilities.updateComponentTreeUI(window);
|
SwingUtilities.updateComponentTreeUI(window);
|
||||||
@@ -273,11 +280,11 @@ public class ThemeManager
|
|||||||
|
|
||||||
if(EventQueue.isDispatchThread())
|
if(EventQueue.isDispatchThread())
|
||||||
{
|
{
|
||||||
r.run();
|
updateRealized.run();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
EventQueue.invokeLater(r);
|
EventQueue.invokeLater(updateRealized);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user