From 78e78392139bfd389705c49b2ecd79a8ef7ec1c5 Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Thu, 22 Sep 2022 23:15:07 +0200 Subject: [PATCH] Window decorations: added option to show window icon only in frames, but not in dialogs (issue #589) --- CHANGELOG.md | 8 +++++--- .../main/java/com/formdev/flatlaf/ui/FlatTitlePane.java | 9 ++++++++- .../resources/com/formdev/flatlaf/FlatLaf.properties | 1 + flatlaf-testing/dumps/uidefaults/FlatDarkLaf_1.8.0.txt | 1 + flatlaf-testing/dumps/uidefaults/FlatLightLaf_1.8.0.txt | 1 + flatlaf-testing/dumps/uidefaults/FlatTestLaf_1.8.0.txt | 1 + .../com/formdev/flatlaf/themeeditor/FlatLafUIKeys.txt | 1 + 7 files changed, 18 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 08c265eb..f6760eec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,9 +14,11 @@ FlatLaf Change Log is disabled. (issue #501) - TabbedPane: New option to disable tab run rotation in wrap layout. Set UI value `TabbedPane.rotateTabRuns` to `false`. (issue #574) -- Native window decorations (Windows 10/11 only): Added client property to mark - components in embedded menu bar as "caption" (allow moving window). (issue - #569) +- Window decorations: + - Added client property to mark components in embedded menu bar as "caption" + (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 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/ui/FlatTitlePane.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTitlePane.java index f7ca89ae..3de5c8c5 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 @@ -55,6 +55,7 @@ import javax.swing.BoxLayout; import javax.swing.Icon; import javax.swing.JButton; import javax.swing.JComponent; +import javax.swing.JDialog; import javax.swing.JLabel; import javax.swing.JMenuBar; import javax.swing.JPanel; @@ -80,6 +81,7 @@ import com.formdev.flatlaf.util.UIScale; * @uiDefault TitlePane.borderColor Color optional * @uiDefault TitlePane.unifiedBackground boolean * @uiDefault TitlePane.showIcon boolean + * @uiDefault TitlePane.showIconInDialogs boolean * @uiDefault TitlePane.noIconLeftGap int * @uiDefault TitlePane.iconSize Dimension * @uiDefault TitlePane.iconMargins Insets @@ -111,6 +113,7 @@ public class FlatTitlePane protected final Color borderColor = UIManager.getColor( "TitlePane.borderColor" ); /** @since 2 */ protected final boolean showIcon = FlatUIUtils.getUIBoolean( "TitlePane.showIcon", true ); + /** @since 2.5 */ protected final boolean showIconInDialogs = FlatUIUtils.getUIBoolean( "TitlePane.showIconInDialogs", true ); /** @since 2 */ protected final int noIconLeftGap = FlatUIUtils.getUIInt( "TitlePane.noIconLeftGap", 8 ); protected final Dimension iconSize = UIManager.getDimension( "TitlePane.iconSize" ); /** @since 2.4 */ protected final int titleMinimumWidth = FlatUIUtils.getUIInt( "TitlePane.titleMinimumWidth", 60 ); @@ -389,9 +392,13 @@ public class FlatTitlePane } protected void updateIcon() { + boolean defaultShowIcon = showIcon; + if( !showIconInDialogs && rootPane.getParent() instanceof JDialog ) + defaultShowIcon = false; + // get window images List images = null; - if( clientPropertyBoolean( rootPane, TITLE_BAR_SHOW_ICON, showIcon ) ) { + if( clientPropertyBoolean( rootPane, TITLE_BAR_SHOW_ICON, defaultShowIcon ) ) { images = window.getIconImages(); if( images.isEmpty() ) { // search in owners diff --git a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLaf.properties b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLaf.properties index 2c50af92..7aedcb79 100644 --- a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLaf.properties +++ b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLaf.properties @@ -785,6 +785,7 @@ TitlePane.useWindowDecorations = true TitlePane.menuBarEmbedded = true TitlePane.unifiedBackground = true TitlePane.showIcon = true +TitlePane.showIconInDialogs = true TitlePane.noIconLeftGap = 8 TitlePane.iconSize = 16,16 TitlePane.iconMargins = 3,8,3,8 diff --git a/flatlaf-testing/dumps/uidefaults/FlatDarkLaf_1.8.0.txt b/flatlaf-testing/dumps/uidefaults/FlatDarkLaf_1.8.0.txt index b0951db1..4b366239 100644 --- a/flatlaf-testing/dumps/uidefaults/FlatDarkLaf_1.8.0.txt +++ b/flatlaf-testing/dumps/uidefaults/FlatDarkLaf_1.8.0.txt @@ -1242,6 +1242,7 @@ TitlePane.noIconLeftGap 8 TitlePane.restoreIcon [lazy] 44,30 com.formdev.flatlaf.icons.FlatWindowRestoreIcon [UI] TitlePane.showIcon true TitlePane.showIconBesideTitle false +TitlePane.showIconInDialogs true TitlePane.titleMargins 3,0,3,0 javax.swing.plaf.InsetsUIResource [UI] TitlePane.titleMinimumWidth 60 TitlePane.unifiedBackground true diff --git a/flatlaf-testing/dumps/uidefaults/FlatLightLaf_1.8.0.txt b/flatlaf-testing/dumps/uidefaults/FlatLightLaf_1.8.0.txt index 8e9d4754..73c49d4b 100644 --- a/flatlaf-testing/dumps/uidefaults/FlatLightLaf_1.8.0.txt +++ b/flatlaf-testing/dumps/uidefaults/FlatLightLaf_1.8.0.txt @@ -1247,6 +1247,7 @@ TitlePane.noIconLeftGap 8 TitlePane.restoreIcon [lazy] 44,30 com.formdev.flatlaf.icons.FlatWindowRestoreIcon [UI] TitlePane.showIcon true TitlePane.showIconBesideTitle false +TitlePane.showIconInDialogs true TitlePane.titleMargins 3,0,3,0 javax.swing.plaf.InsetsUIResource [UI] TitlePane.titleMinimumWidth 60 TitlePane.unifiedBackground true diff --git a/flatlaf-testing/dumps/uidefaults/FlatTestLaf_1.8.0.txt b/flatlaf-testing/dumps/uidefaults/FlatTestLaf_1.8.0.txt index 2d5af5f2..b4deece5 100644 --- a/flatlaf-testing/dumps/uidefaults/FlatTestLaf_1.8.0.txt +++ b/flatlaf-testing/dumps/uidefaults/FlatTestLaf_1.8.0.txt @@ -1275,6 +1275,7 @@ TitlePane.noIconLeftGap 8 TitlePane.restoreIcon [lazy] 44,30 com.formdev.flatlaf.icons.FlatWindowRestoreIcon [UI] TitlePane.showIcon true TitlePane.showIconBesideTitle false +TitlePane.showIconInDialogs true TitlePane.titleMargins 3,0,3,0 javax.swing.plaf.InsetsUIResource [UI] TitlePane.titleMinimumWidth 60 TitlePane.unifiedBackground true 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 7e0db84e..5e1a1a7f 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 @@ -1012,6 +1012,7 @@ TitlePane.noIconLeftGap TitlePane.restoreIcon TitlePane.showIcon TitlePane.showIconBesideTitle +TitlePane.showIconInDialogs TitlePane.titleMargins TitlePane.titleMinimumWidth TitlePane.unifiedBackground