FlatTestFrame: fixed exception when using FlatPropertiesLaf and changing scale factor, which re-sets the current Laf

This commit is contained in:
Karl Tauber
2020-11-18 18:45:13 +01:00
parent 06cab0d4b5
commit 59879f493e
2 changed files with 19 additions and 3 deletions

View File

@@ -88,6 +88,10 @@ public class FlatPropertiesLaf
return dark; return dark;
} }
public Properties getProperties() {
return properties;
}
@Override @Override
protected ArrayList<Class<?>> getLafClassesForDefaultsLoading() { protected ArrayList<Class<?>> getLafClassesForDefaultsLoading() {
ArrayList<Class<?>> lafClasses = new ArrayList<>(); ArrayList<Class<?>> lafClasses = new ArrayList<>();

View File

@@ -22,6 +22,7 @@ import java.awt.event.ComponentEvent;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter; import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent; import java.awt.event.WindowEvent;
import java.util.Properties;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
import java.util.function.Function; import java.util.function.Function;
import java.util.function.Supplier; import java.util.function.Supplier;
@@ -35,6 +36,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.FlatPropertiesLaf;
import com.formdev.flatlaf.FlatSystemProperties; import com.formdev.flatlaf.FlatSystemProperties;
import com.formdev.flatlaf.IntelliJTheme; import com.formdev.flatlaf.IntelliJTheme;
import com.formdev.flatlaf.demo.LookAndFeelsComboBox; import com.formdev.flatlaf.demo.LookAndFeelsComboBox;
@@ -331,10 +333,12 @@ public class FlatTestFrame
// hide popup to avoid occasional StackOverflowError when updating UI // hide popup to avoid occasional StackOverflowError when updating UI
lookAndFeelComboBox.setPopupVisible( false ); lookAndFeelComboBox.setPopupVisible( false );
applyLookAndFeel( lafClassName, null, false ); applyLookAndFeel( lafClassName, null, null, null, false );
} }
private void applyLookAndFeel( String lafClassName, IntelliJTheme theme, boolean pack ) { private void applyLookAndFeel( String lafClassName, IntelliJTheme theme,
String nameForProperties, Properties properties, boolean pack )
{
EventQueue.invokeLater( () -> { EventQueue.invokeLater( () -> {
try { try {
// clear custom default font before switching to other LaF // clear custom default font before switching to other LaF
@@ -349,6 +353,8 @@ public class FlatTestFrame
// change look and feel // change look and feel
if( theme != null ) if( theme != null )
UIManager.setLookAndFeel( IntelliJTheme.createLaf( theme ) ); UIManager.setLookAndFeel( IntelliJTheme.createLaf( theme ) );
else if( properties != null )
UIManager.setLookAndFeel( new FlatPropertiesLaf( nameForProperties, properties ) );
else else
UIManager.setLookAndFeel( lafClassName ); UIManager.setLookAndFeel( lafClassName );
@@ -507,7 +513,13 @@ public class FlatTestFrame
IntelliJTheme theme = (lookAndFeel instanceof IntelliJTheme.ThemeLaf) IntelliJTheme theme = (lookAndFeel instanceof IntelliJTheme.ThemeLaf)
? ((IntelliJTheme.ThemeLaf)lookAndFeel).getTheme() ? ((IntelliJTheme.ThemeLaf)lookAndFeel).getTheme()
: null; : null;
applyLookAndFeel( lookAndFeel.getClass().getName(), theme, true ); String nameForProperties = null;
Properties properties = null;
if( lookAndFeel instanceof FlatPropertiesLaf ) {
nameForProperties = lookAndFeel.getName();
properties = ((FlatPropertiesLaf)lookAndFeel).getProperties();
}
applyLookAndFeel( lookAndFeel.getClass().getName(), theme, nameForProperties, properties, true );
} }
private void updateScaleFactorComboBox() { private void updateScaleFactorComboBox() {