Skip to content

Commit

Permalink
Dynamic dark and light mode.
Browse files Browse the repository at this point in the history
- Known issues: Text formatting is ruined when switching dynamically
  • Loading branch information
CoocooFroggy committed Mar 4, 2021
1 parent ca4b00f commit 6283163
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions src/main/java/MainMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -377,13 +377,33 @@ public void actionPerformed(ActionEvent e) {
final OsThemeDetector detector = OsThemeDetector.getDetector();
detector.registerListener(isDark -> {
if (isDark) {
FlatDarculaLaf.install();
System.out.println("Darkened");
mainMenuView.revalidate();
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
FlatDarculaLaf.install();
System.out.println("Darkened");
FlatDarculaLaf.updateUI();
}
});
} else {
FlatIntelliJLaf.install();
System.out.println("Lightened");
mainMenuView.revalidate();
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
if (System.getProperty("os.name").equals("Mac OS X")) {
//Return to Mac light mode
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) {
e.printStackTrace();
}
SwingUtilities.updateComponentTreeUI(mainMenuView);
} else {
FlatIntelliJLaf.install();
System.out.println("Lightened");
FlatIntelliJLaf.updateUI();
}
}
});
}
});
}
Expand Down

0 comments on commit 6283163

Please sign in to comment.