linux UI dark theme fixes

This commit is contained in:
Radek Davidek 2026-01-26 10:29:36 +01:00
parent 8370e1cf76
commit eec2973b0a
6 changed files with 161 additions and 14 deletions

View File

@ -49,8 +49,22 @@ public class MainApp {
} else { } else {
FlatLightLaf.setup(); FlatLightLaf.setup();
} }
} else if (CURRENT_OS == OS.LINUX) {
// On Linux, use FlatLaf and detect system theme (light/dark)
if (isLinuxDarkMode()) {
FlatDarkLaf.setup();
} else { } else {
// On Linux and macOS, use FlatLaf as a better-looking alternative FlatLightLaf.setup();
}
} else if (CURRENT_OS == OS.MACOS) {
// On macOS, use FlatLaf and detect system theme (light/dark)
if (isMacDarkMode()) {
FlatDarkLaf.setup();
} else {
FlatLightLaf.setup();
}
} else {
// On other OS, use FlatLaf as a better-looking alternative
// to the default system L&F // to the default system L&F
FlatLightLaf.setup(); FlatLightLaf.setup();
} }
@ -88,6 +102,40 @@ public class MainApp {
return false; return false;
} }
private static boolean isLinuxDarkMode() {
try {
// Check for GNOME/Cinnamon/MATE dark mode preference via gsettings
Process process = Runtime.getRuntime().exec(new String[]{"gsettings", "get", "org.gnome.desktop.interface", "color-scheme"});
try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
String line = reader.readLine();
if (line != null && line.contains("dark")) return true;
}
// Fallback: Check GTK theme name
process = Runtime.getRuntime().exec(new String[]{"gsettings", "get", "org.gnome.desktop.interface", "gtk-theme"});
try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
String line = reader.readLine();
if (line != null && line.toLowerCase().contains("dark")) return true;
}
} catch (Exception e) {
// ignore
}
return false;
}
private static boolean isMacDarkMode() {
try {
Process process = Runtime.getRuntime().exec(new String[]{"defaults", "read", "-g", "AppleInterfaceStyle"});
try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
String line = reader.readLine();
return line != null && line.contains("Dark");
}
} catch (Exception e) {
// ignore
}
return false;
}
private static void setupGlobalKeyNavigation() { private static void setupGlobalKeyNavigation() {
Toolkit.getDefaultToolkit().addAWTEventListener(event -> { Toolkit.getDefaultToolkit().addAWTEventListener(event -> {
if (event instanceof KeyEvent) { if (event instanceof KeyEvent) {

View File

@ -216,11 +216,28 @@ public class FilePanelTab extends JPanel {
container.setBackground(bg); container.setBackground(bg);
boolean dark = isDark(bg); boolean dark = isDark(bg);
for (Component c : container.getComponents()) { for (Component c : container.getComponents()) {
if (c instanceof JPanel || c instanceof JToolBar || c instanceof JScrollPane || c instanceof JViewport || c instanceof JTabbedPane) { if (c instanceof JPanel || c instanceof JToolBar || c instanceof JScrollPane || c instanceof JViewport ||
c instanceof JTabbedPane || c instanceof JSplitPane || c instanceof JList ||
c instanceof JComboBox || c instanceof JTable || c instanceof JButton) {
c.setBackground(bg); c.setBackground(bg);
} else if (c instanceof JLabel || c instanceof JCheckBox || c instanceof JRadioButton) { if (c instanceof JTable) {
JTable t = (JTable) c;
if (t.getTableHeader() != null) {
t.getTableHeader().setBackground(bg);
t.getTableHeader().setForeground(dark ? Color.WHITE : Color.BLACK);
}
}
}
if (c instanceof JLabel || c instanceof JCheckBox || c instanceof JRadioButton ||
c instanceof JButton || c instanceof JComboBox || c instanceof JList) {
c.setForeground(dark ? Color.WHITE : Color.BLACK); c.setForeground(dark ? Color.WHITE : Color.BLACK);
} }
if (c instanceof javax.swing.text.JTextComponent) {
javax.swing.text.JTextComponent tc = (javax.swing.text.JTextComponent) c;
tc.setBackground(bg);
tc.setForeground(dark ? Color.WHITE : Color.BLACK);
tc.setCaretColor(dark ? Color.WHITE : Color.BLACK);
}
if (c instanceof Container) { if (c instanceof Container) {
updateComponentBackground((Container) c, bg); updateComponentBackground((Container) c, bg);
} }

View File

@ -1016,10 +1016,20 @@ public class MainWindow extends JFrame {
Color selColor = config != null ? config.getSelectionColor() : null; Color selColor = config != null ? config.getSelectionColor() : null;
for (Component c : container.getComponents()) { for (Component c : container.getComponents()) {
if (c instanceof JPanel || c instanceof JToolBar || c instanceof JScrollPane || c instanceof JViewport || c instanceof JTabbedPane || c instanceof JButton) { if (c instanceof JPanel || c instanceof JToolBar || c instanceof JScrollPane || c instanceof JViewport ||
c instanceof JTabbedPane || c instanceof JButton || c instanceof JSplitPane ||
c instanceof JList || c instanceof JComboBox || c instanceof JTable) {
c.setBackground(bg); c.setBackground(bg);
if (c instanceof JTable) {
JTable t = (JTable) c;
if (t.getTableHeader() != null) {
t.getTableHeader().setBackground(bg);
t.getTableHeader().setForeground(dark ? Color.WHITE : Color.BLACK);
} }
if (c instanceof JLabel || c instanceof JCheckBox || c instanceof JRadioButton || c instanceof JButton) { }
}
if (c instanceof JLabel || c instanceof JCheckBox || c instanceof JRadioButton ||
c instanceof JButton || c instanceof JComboBox || c instanceof JList) {
c.setForeground(dark ? Color.WHITE : Color.BLACK); c.setForeground(dark ? Color.WHITE : Color.BLACK);
} }
if (c instanceof javax.swing.text.JTextComponent) { if (c instanceof javax.swing.text.JTextComponent) {
@ -1031,6 +1041,19 @@ public class MainWindow extends JFrame {
tc.setSelectionColor(selColor); tc.setSelectionColor(selColor);
} }
} }
if (c instanceof JComboBox) {
JComboBox<?> cb = (JComboBox<?>) c;
Component ed = cb.getEditor().getEditorComponent();
if (ed instanceof javax.swing.text.JTextComponent) {
javax.swing.text.JTextComponent tc = (javax.swing.text.JTextComponent) ed;
tc.setBackground(bg);
tc.setForeground(dark ? Color.WHITE : Color.BLACK);
tc.setCaretColor(dark ? Color.WHITE : Color.BLACK);
if (selColor != null) {
tc.setSelectionColor(selColor);
}
}
}
if (c instanceof Container) { if (c instanceof Container) {
updateComponentBackground((Container) c, bg); updateComponentBackground((Container) c, bg);
} }

View File

@ -75,10 +75,20 @@ public class SearchDialog extends JDialog {
Color selColor = config != null ? config.getSelectionColor() : null; Color selColor = config != null ? config.getSelectionColor() : null;
for (Component c : container.getComponents()) { for (Component c : container.getComponents()) {
if (c instanceof JPanel || c instanceof JScrollPane || c instanceof JViewport || c instanceof JTabbedPane || c instanceof JButton || c instanceof JComboBox) { if (c instanceof JPanel || c instanceof JToolBar || c instanceof JScrollPane || c instanceof JViewport ||
c instanceof JTabbedPane || c instanceof JButton || c instanceof JSplitPane ||
c instanceof JList || c instanceof JComboBox || c instanceof JTable) {
c.setBackground(bg); c.setBackground(bg);
if (c instanceof JTable) {
JTable t = (JTable) c;
if (t.getTableHeader() != null) {
t.getTableHeader().setBackground(bg);
t.getTableHeader().setForeground(dark ? Color.WHITE : Color.BLACK);
} }
if (c instanceof JLabel || c instanceof JCheckBox || c instanceof JRadioButton || c instanceof JButton) { }
}
if (c instanceof JLabel || c instanceof JCheckBox || c instanceof JRadioButton ||
c instanceof JButton || c instanceof JComboBox || c instanceof JList) {
c.setForeground(dark ? Color.WHITE : Color.BLACK); c.setForeground(dark ? Color.WHITE : Color.BLACK);
} }
if (c instanceof javax.swing.text.JTextComponent) { if (c instanceof javax.swing.text.JTextComponent) {
@ -92,12 +102,15 @@ public class SearchDialog extends JDialog {
} }
if (c instanceof JComboBox) { if (c instanceof JComboBox) {
JComboBox<?> cb = (JComboBox<?>) c; JComboBox<?> cb = (JComboBox<?>) c;
Component editor = cb.getEditor().getEditorComponent(); Component ed = cb.getEditor().getEditorComponent();
if (editor instanceof javax.swing.text.JTextComponent) { if (ed instanceof javax.swing.text.JTextComponent) {
javax.swing.text.JTextComponent tc = (javax.swing.text.JTextComponent) editor; javax.swing.text.JTextComponent tc = (javax.swing.text.JTextComponent) ed;
tc.setBackground(bg); tc.setBackground(bg);
tc.setForeground(dark ? Color.WHITE : Color.BLACK); tc.setForeground(dark ? Color.WHITE : Color.BLACK);
tc.setCaretColor(dark ? Color.WHITE : Color.BLACK); tc.setCaretColor(dark ? Color.WHITE : Color.BLACK);
if (selColor != null) {
tc.setSelectionColor(selColor);
}
} }
} }
if (c instanceof Container) { if (c instanceof Container) {

View File

@ -275,10 +275,20 @@ public class SettingsDialog extends JDialog {
continue; continue;
} }
if (c instanceof JPanel || c instanceof JScrollPane || c instanceof JViewport || c instanceof JTabbedPane || c instanceof JButton || c instanceof JSplitPane || c instanceof JList) { if (c instanceof JPanel || c instanceof JToolBar || c instanceof JScrollPane || c instanceof JViewport ||
c instanceof JTabbedPane || c instanceof JButton || c instanceof JSplitPane ||
c instanceof JList || c instanceof JComboBox || c instanceof JTable) {
c.setBackground(bg); c.setBackground(bg);
if (c instanceof JTable) {
JTable t = (JTable) c;
if (t.getTableHeader() != null) {
t.getTableHeader().setBackground(bg);
t.getTableHeader().setForeground(dark ? Color.WHITE : Color.BLACK);
} }
if (c instanceof JLabel || c instanceof JCheckBox || c instanceof JRadioButton || c instanceof JButton || c instanceof JList) { }
}
if (c instanceof JLabel || c instanceof JCheckBox || c instanceof JRadioButton ||
c instanceof JButton || c instanceof JComboBox || c instanceof JList) {
c.setForeground(dark ? Color.WHITE : Color.BLACK); c.setForeground(dark ? Color.WHITE : Color.BLACK);
} }
if (c instanceof javax.swing.text.JTextComponent) { if (c instanceof javax.swing.text.JTextComponent) {
@ -290,6 +300,19 @@ public class SettingsDialog extends JDialog {
tc.setSelectionColor(selColor); tc.setSelectionColor(selColor);
} }
} }
if (c instanceof JComboBox) {
JComboBox<?> cb = (JComboBox<?>) c;
Component ed = cb.getEditor().getEditorComponent();
if (ed instanceof javax.swing.text.JTextComponent) {
javax.swing.text.JTextComponent tc = (javax.swing.text.JTextComponent) ed;
tc.setBackground(bg);
tc.setForeground(dark ? Color.WHITE : Color.BLACK);
tc.setCaretColor(dark ? Color.WHITE : Color.BLACK);
if (selColor != null) {
tc.setSelectionColor(selColor);
}
}
}
if (c instanceof Container) { if (c instanceof Container) {
updateComponentBackground((Container) c, bg); updateComponentBackground((Container) c, bg);
} }

View File

@ -279,12 +279,22 @@ public class SyncDirectoriesDialog extends JDialog {
Color selColor = config != null ? config.getSelectionColor() : null; Color selColor = config != null ? config.getSelectionColor() : null;
for (Component c : container.getComponents()) { for (Component c : container.getComponents()) {
if (c instanceof JPanel || c instanceof JScrollPane || c instanceof JViewport || c instanceof JTabbedPane || c instanceof AbstractButton || c instanceof JComboBox || c instanceof JTable) { if (c instanceof JPanel || c instanceof JToolBar || c instanceof JScrollPane || c instanceof JViewport ||
c instanceof JTabbedPane || c instanceof AbstractButton || c instanceof JSplitPane ||
c instanceof JList || c instanceof JComboBox || c instanceof JTable) {
if (!(c instanceof JToggleButton)) { if (!(c instanceof JToggleButton)) {
c.setBackground(bg); c.setBackground(bg);
} }
if (c instanceof JTable) {
JTable t = (JTable) c;
if (t.getTableHeader() != null) {
t.getTableHeader().setBackground(bg);
t.getTableHeader().setForeground(dark ? Color.WHITE : Color.BLACK);
} }
if (c instanceof JLabel || c instanceof JCheckBox || c instanceof JRadioButton || c instanceof AbstractButton) { }
}
if (c instanceof JLabel || c instanceof JCheckBox || c instanceof JRadioButton ||
c instanceof AbstractButton || c instanceof JComboBox || c instanceof JList) {
if (!(c instanceof JToggleButton)) { if (!(c instanceof JToggleButton)) {
c.setForeground(dark ? Color.WHITE : Color.BLACK); c.setForeground(dark ? Color.WHITE : Color.BLACK);
} }
@ -298,6 +308,19 @@ public class SyncDirectoriesDialog extends JDialog {
tc.setSelectionColor(selColor); tc.setSelectionColor(selColor);
} }
} }
if (c instanceof JComboBox) {
JComboBox<?> cb = (JComboBox<?>) c;
Component ed = cb.getEditor().getEditorComponent();
if (ed instanceof javax.swing.text.JTextComponent) {
javax.swing.text.JTextComponent tc = (javax.swing.text.JTextComponent) ed;
tc.setBackground(bg);
tc.setForeground(dark ? Color.WHITE : Color.BLACK);
tc.setCaretColor(dark ? Color.WHITE : Color.BLACK);
if (selColor != null) {
tc.setSelectionColor(selColor);
}
}
}
if (c instanceof Container) { if (c instanceof Container) {
updateComponentBackground((Container) c, bg); updateComponentBackground((Container) c, bg);
} }