FlatTestFrame: fixed exception when changing scale factor (when running in Java 8)

This commit is contained in:
Karl Tauber
2019-11-13 10:48:20 +01:00
parent 0bef71907c
commit da0c562ac2
2 changed files with 16 additions and 4 deletions

View File

@@ -329,6 +329,10 @@ public class IntelliJTheme
return theme.dark; return theme.dark;
} }
public IntelliJTheme getTheme() {
return theme;
}
@Override @Override
public UIDefaults getDefaults() { public UIDefaults getDefaults() {
UIDefaults defaults = super.getDefaults(); UIDefaults defaults = super.getDefaults();

View File

@@ -35,6 +35,7 @@ import com.formdev.flatlaf.FlatDarkLaf;
import com.formdev.flatlaf.FlatIntelliJLaf; import com.formdev.flatlaf.FlatIntelliJLaf;
import com.formdev.flatlaf.FlatLaf; import com.formdev.flatlaf.FlatLaf;
import com.formdev.flatlaf.FlatLightLaf; import com.formdev.flatlaf.FlatLightLaf;
import com.formdev.flatlaf.IntelliJTheme;
import com.formdev.flatlaf.demo.LookAndFeelsComboBox; import com.formdev.flatlaf.demo.LookAndFeelsComboBox;
import com.formdev.flatlaf.demo.intellijthemes.*; import com.formdev.flatlaf.demo.intellijthemes.*;
import com.formdev.flatlaf.extras.*; import com.formdev.flatlaf.extras.*;
@@ -240,14 +241,17 @@ public class FlatTestFrame
Preferences.userRoot().node( PREFS_ROOT_PATH ).put( KEY_LAF, lafClassName ); Preferences.userRoot().node( PREFS_ROOT_PATH ).put( KEY_LAF, lafClassName );
applyLookAndFeel( lafClassName, false ); applyLookAndFeel( lafClassName, null, false );
} }
private void applyLookAndFeel( String lafClassName, boolean pack ) { private void applyLookAndFeel( String lafClassName, IntelliJTheme theme, boolean pack ) {
EventQueue.invokeLater( () -> { EventQueue.invokeLater( () -> {
try { try {
// change look and feel // change look and feel
UIManager.setLookAndFeel( lafClassName ); if( theme != null )
UIManager.setLookAndFeel( IntelliJTheme.createLaf( theme ) );
else
UIManager.setLookAndFeel( lafClassName );
// update all components // update all components
FlatLaf.updateUI(); FlatLaf.updateUI();
@@ -364,7 +368,11 @@ public class FlatTestFrame
prefs.remove( KEY_SCALE_FACTOR ); prefs.remove( KEY_SCALE_FACTOR );
} }
applyLookAndFeel( UIManager.getLookAndFeel().getClass().getName(), true ); LookAndFeel lookAndFeel = UIManager.getLookAndFeel();
IntelliJTheme theme = (lookAndFeel instanceof IntelliJTheme.ThemeLaf)
? ((IntelliJTheme.ThemeLaf)lookAndFeel).getTheme()
: null;
applyLookAndFeel( lookAndFeel.getClass().getName(), theme, true );
} }
private void updateScaleFactorComboBox() { private void updateScaleFactorComboBox() {