@@ -368,6 +368,22 @@ else if( DESKTOPFONTHINTS.equals( propertyName ) ) {
368368 String .format ( "a, address { color: #%06x; }" , linkColor .getRGB () & 0xffffff ) );
369369 }
370370 };
371+
372+ // Initialize UIScale user scale factor immediately after FlatLaf was activated,
373+ // which is necessary to ensure that UIScale.setZoomFactor(float)
374+ // scales FlatLaf defaultDont correctly even if UIScale.scale() was not yet used.
375+ // In other words: Without this, UIScale.setZoomFactor(float) would
376+ // not work correctly if invoked between FlatLaf.setup() and crating UI.
377+ PropertyChangeListener listener = new PropertyChangeListener () {
378+ @ Override
379+ public void propertyChange ( PropertyChangeEvent e ) {
380+ if ( "lookAndFeel" .equals ( e .getPropertyName () ) ) {
381+ UIManager .removePropertyChangeListener ( this );
382+ UIScale .getUserScaleFactor ();
383+ }
384+ }
385+ };
386+ UIManager .addPropertyChangeListener ( listener );
371387 }
372388
373389 @ Override
@@ -707,11 +723,22 @@ private void initDefaultFont( UIDefaults defaults ) {
707723 uiFont = ((ActiveFont )defaultFont ).derive ( baseFont , fontSize -> {
708724 return Math .round ( fontSize * UIScale .computeFontScaleFactor ( baseFont ) );
709725 } );
710- }
726+ } else if ( defaultFont instanceof LazyValue )
727+ uiFont = ActiveFont .toUIResource ( (Font ) ((LazyValue )defaultFont ).createValue ( defaults ) );
711728
712729 // increase font size if system property "flatlaf.uiScale" is set
713730 uiFont = UIScale .applyCustomScaleFactor ( uiFont );
714731
732+ // apply zoom factor to font size
733+ float zoomFactor = UIScale .getZoomFactor ();
734+ if ( zoomFactor != 1 ) {
735+ // see also UIScale.setZoomFactor()
736+ int unzoomedFontSize = uiFont .getSize ();
737+ defaults .put ( "defaultFont.unzoomedSize" , unzoomedFontSize );
738+ int newFontSize = Math .max ( Math .round ( unzoomedFontSize * zoomFactor ), 1 );
739+ uiFont = new FontUIResource ( uiFont .deriveFont ( (float ) newFontSize ) );
740+ }
741+
715742 // set default font
716743 defaults .put ( "defaultFont" , uiFont );
717744 }
@@ -1768,7 +1795,7 @@ FontUIResource derive( Font baseFont, IntUnaryOperator scale ) {
17681795 return toUIResource ( baseFont );
17691796 }
17701797
1771- private FontUIResource toUIResource ( Font font ) {
1798+ private static FontUIResource toUIResource ( Font font ) {
17721799 // make sure that font is a UIResource for LaF switching
17731800 return (font instanceof FontUIResource )
17741801 ? (FontUIResource ) font
0 commit comments