JIDE: fixed null font in other Lafs if (wrongly) using LookAndFeelFactory.addUIDefaultsInitializer() or LookAndFeelFactory.addUIDefaultsCustomizer() (issue #288)

This commit is contained in:
Karl Tauber
2021-04-06 18:35:48 +02:00
parent 277c288952
commit e35fc8620c
2 changed files with 16 additions and 0 deletions

View File

@@ -833,6 +833,10 @@ public abstract class FlatLaf
public Object createValue( UIDefaults table ) { public Object createValue( UIDefaults table ) {
Font defaultFont = UIManager.getFont( "defaultFont" ); Font defaultFont = UIManager.getFont( "defaultFont" );
// fallback (to avoid NPE in case that this is used in another Laf)
if( defaultFont == null )
defaultFont = UIManager.getFont( "Label.font" );
if( lastDefaultFont != defaultFont ) { if( lastDefaultFont != defaultFont ) {
lastDefaultFont = defaultFont; lastDefaultFont = defaultFont;

View File

@@ -21,6 +21,7 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import javax.swing.LookAndFeel; import javax.swing.LookAndFeel;
import javax.swing.UIDefaults; import javax.swing.UIDefaults;
import javax.swing.UIManager;
import javax.swing.UIDefaults.ActiveValue; import javax.swing.UIDefaults.ActiveValue;
import com.formdev.flatlaf.FlatDefaultsAddon; import com.formdev.flatlaf.FlatDefaultsAddon;
import com.formdev.flatlaf.FlatLaf; import com.formdev.flatlaf.FlatLaf;
@@ -70,6 +71,9 @@ public class FlatJideOssDefaultsAddon
* own UI defaults, we have to first remember our UI defaults in the initializer * own UI defaults, we have to first remember our UI defaults in the initializer
* (invoked before JIDE overwrites UI defaults) and then restore them in the customizer. * (invoked before JIDE overwrites UI defaults) and then restore them in the customizer.
* <p> * <p>
* Do not register this class yourself with JIDE.
* It is automatically registered.
* <p>
* Invoked from {@link LookAndFeelFactory#installJideExtension()}. * Invoked from {@link LookAndFeelFactory#installJideExtension()}.
*/ */
public static class FlatJideUIDefaultsCustomizer public static class FlatJideUIDefaultsCustomizer
@@ -79,6 +83,10 @@ public class FlatJideOssDefaultsAddon
@Override @Override
public void initialize( UIDefaults defaults ) { public void initialize( UIDefaults defaults ) {
// do nothing in other Lafs if (wrongly) registered with LookAndFeelFactory.addUIDefaultsInitializer()
if( !(UIManager.getLookAndFeel() instanceof FlatLaf) )
return;
jideDefaults = new HashMap<>(); jideDefaults = new HashMap<>();
for( Map.Entry<Object, Object> e : defaults.entrySet() ) { for( Map.Entry<Object, Object> e : defaults.entrySet() ) {
@@ -96,6 +104,10 @@ public class FlatJideOssDefaultsAddon
@Override @Override
public void customize( UIDefaults defaults ) { public void customize( UIDefaults defaults ) {
// do nothing in other Lafs if (wrongly) registered with LookAndFeelFactory.addUIDefaultsCustomizer()
if( !(UIManager.getLookAndFeel() instanceof FlatLaf) )
return;
if( jideDefaults != null ) { if( jideDefaults != null ) {
defaults.putAll( jideDefaults ); defaults.putAll( jideDefaults );
jideDefaults = null; jideDefaults = null;