From c228362c0185e204ae051ed9ca82b97255e2192e Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Fri, 23 Sep 2022 11:57:38 +0200 Subject: [PATCH] Window decorations: added UI value `TitlePane.font` to customize window title font (issue #589) --- CHANGELOG.md | 1 + .../src/main/java/com/formdev/flatlaf/FlatLaf.java | 1 + .../java/com/formdev/flatlaf/ui/FlatTitlePane.java | 11 +++++++++++ .../dumps/uidefaults/FlatDarkLaf_1.8.0.txt | 1 + .../dumps/uidefaults/FlatLightLaf_1.8.0.txt | 1 + .../dumps/uidefaults/FlatTestLaf_1.8.0.txt | 1 + .../com/formdev/flatlaf/themeeditor/FlatLafUIKeys.txt | 1 + 7 files changed, 17 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c428b7c2..ffe7f608 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ FlatLaf Change Log (allow moving window). (issue #569) - Option to show window icon only in frames, but not in dialogs. Set UI value `TitlePane.showIconInDialogs` to `false`. (issue #589) + - Added UI value `TitlePane.font` to customize window title font. (issue #589) - Added system property `flatlaf.updateUIOnSystemFontChange` to allow disabling automatic UI update when system font changes. (issue #580) diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatLaf.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatLaf.java index 50da9264..dde7fa14 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatLaf.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatLaf.java @@ -581,6 +581,7 @@ public abstract class FlatLaf // add fonts that are not set in BasicLookAndFeel defaults.put( "RootPane.font", activeFont ); + defaults.put( "TitlePane.font", activeFont ); } private void initDefaultFont( UIDefaults defaults ) { diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTitlePane.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTitlePane.java index 3de5c8c5..7194bee3 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTitlePane.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTitlePane.java @@ -24,6 +24,7 @@ import java.awt.Container; import java.awt.Dialog; import java.awt.Dimension; import java.awt.EventQueue; +import java.awt.Font; import java.awt.FontMetrics; import java.awt.Frame; import java.awt.Graphics; @@ -73,6 +74,7 @@ import com.formdev.flatlaf.util.UIScale; /** * Provides the Flat LaF title bar. * + * @uiDefault TitlePane.font Font * @uiDefault TitlePane.background Color * @uiDefault TitlePane.inactiveBackground Color * @uiDefault TitlePane.foreground Color @@ -105,6 +107,7 @@ import com.formdev.flatlaf.util.UIScale; public class FlatTitlePane extends JComponent { + /** @since 2.5 */ protected final Font titleFont = UIManager.getFont( "TitlePane.font" ); protected final Color activeBackground = UIManager.getColor( "TitlePane.background" ); protected final Color inactiveBackground = UIManager.getColor( "TitlePane.inactiveBackground" ); protected final Color activeForeground = UIManager.getColor( "TitlePane.foreground" ); @@ -1012,6 +1015,14 @@ debug*/ super( false ); } + @Override + protected void installDefaults( JLabel c ) { + super.installDefaults( c ); + + if( titleFont != null ) + c.setFont( titleFont ); + } + @Override protected String layoutCL( JLabel label, FontMetrics fontMetrics, String text, Icon icon, Rectangle viewR, Rectangle iconR, Rectangle textR ) diff --git a/flatlaf-testing/dumps/uidefaults/FlatDarkLaf_1.8.0.txt b/flatlaf-testing/dumps/uidefaults/FlatDarkLaf_1.8.0.txt index 4b366239..61c89e18 100644 --- a/flatlaf-testing/dumps/uidefaults/FlatDarkLaf_1.8.0.txt +++ b/flatlaf-testing/dumps/uidefaults/FlatDarkLaf_1.8.0.txt @@ -1226,6 +1226,7 @@ TitlePane.closeIcon [lazy] 44,30 com.formdev.flatlaf.icons.FlatWin TitlePane.closePressedBackground #c42b1ce6 90% HSLA 5 75 44 90 javax.swing.plaf.ColorUIResource [UI] TitlePane.closePressedForeground #ffffff HSL 0 0 100 javax.swing.plaf.ColorUIResource [UI] TitlePane.embeddedForeground #959595 HSL 0 0 58 javax.swing.plaf.ColorUIResource [UI] +TitlePane.font [active] $defaultFont [UI] TitlePane.foreground #bbbbbb HSL 0 0 73 javax.swing.plaf.ColorUIResource [UI] TitlePane.icon [lazy] 16,16 sun.swing.ImageIconUIResource [UI] (sun.awt.image.ToolkitImage) TitlePane.iconMargins 3,8,3,8 javax.swing.plaf.InsetsUIResource [UI] diff --git a/flatlaf-testing/dumps/uidefaults/FlatLightLaf_1.8.0.txt b/flatlaf-testing/dumps/uidefaults/FlatLightLaf_1.8.0.txt index 73c49d4b..73a039f0 100644 --- a/flatlaf-testing/dumps/uidefaults/FlatLightLaf_1.8.0.txt +++ b/flatlaf-testing/dumps/uidefaults/FlatLightLaf_1.8.0.txt @@ -1231,6 +1231,7 @@ TitlePane.closeIcon [lazy] 44,30 com.formdev.flatlaf.icons.FlatWin TitlePane.closePressedBackground #c42b1ce6 90% HSLA 5 75 44 90 javax.swing.plaf.ColorUIResource [UI] TitlePane.closePressedForeground #ffffff HSL 0 0 100 javax.swing.plaf.ColorUIResource [UI] TitlePane.embeddedForeground #595959 HSL 0 0 35 javax.swing.plaf.ColorUIResource [UI] +TitlePane.font [active] $defaultFont [UI] TitlePane.foreground #000000 HSL 0 0 0 javax.swing.plaf.ColorUIResource [UI] TitlePane.icon [lazy] 16,16 sun.swing.ImageIconUIResource [UI] (sun.awt.image.ToolkitImage) TitlePane.iconMargins 3,8,3,8 javax.swing.plaf.InsetsUIResource [UI] diff --git a/flatlaf-testing/dumps/uidefaults/FlatTestLaf_1.8.0.txt b/flatlaf-testing/dumps/uidefaults/FlatTestLaf_1.8.0.txt index b4deece5..ecce697a 100644 --- a/flatlaf-testing/dumps/uidefaults/FlatTestLaf_1.8.0.txt +++ b/flatlaf-testing/dumps/uidefaults/FlatTestLaf_1.8.0.txt @@ -1259,6 +1259,7 @@ TitlePane.closeHoverForeground #ffffff HSL 0 0 100 javax.swing.plaf.Colo TitlePane.closeIcon [lazy] 44,30 com.formdev.flatlaf.icons.FlatWindowCloseIcon [UI] TitlePane.closePressedBackground #c42b1ce6 90% HSLA 5 75 44 90 javax.swing.plaf.ColorUIResource [UI] TitlePane.closePressedForeground #ffffff HSL 0 0 100 javax.swing.plaf.ColorUIResource [UI] +TitlePane.font [active] $defaultFont [UI] TitlePane.foreground #0000ff HSL 240 100 50 javax.swing.plaf.ColorUIResource [UI] TitlePane.icon [lazy] 16,16 sun.swing.ImageIconUIResource [UI] (sun.awt.image.ToolkitImage) TitlePane.iconMargins 3,8,3,8 javax.swing.plaf.InsetsUIResource [UI] diff --git a/flatlaf-theme-editor/src/main/resources/com/formdev/flatlaf/themeeditor/FlatLafUIKeys.txt b/flatlaf-theme-editor/src/main/resources/com/formdev/flatlaf/themeeditor/FlatLafUIKeys.txt index 5e1a1a7f..b5fbc2c6 100644 --- a/flatlaf-theme-editor/src/main/resources/com/formdev/flatlaf/themeeditor/FlatLafUIKeys.txt +++ b/flatlaf-theme-editor/src/main/resources/com/formdev/flatlaf/themeeditor/FlatLafUIKeys.txt @@ -996,6 +996,7 @@ TitlePane.closeIcon TitlePane.closePressedBackground TitlePane.closePressedForeground TitlePane.embeddedForeground +TitlePane.font TitlePane.foreground TitlePane.icon TitlePane.iconMargins