From 15328b4fd7641bcb20308ae2b5addbff0d260c97 Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Wed, 13 Jan 2021 17:52:05 +0100 Subject: [PATCH] ToggleButton: tab style buttons now respect explicitly set background color --- CHANGELOG.md | 2 ++ .../com/formdev/flatlaf/ui/FlatToggleButtonUI.java | 11 +++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c9a9c081..f0d0f6fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,8 @@ FlatLaf Change Log - Button and ToggleButton: ToolBar buttons now respect explicitly set background color. If no background color is set, then the button background is not painted anymore. (issue #191) +- ToggleButton: Tab style buttons (client property `JButton.buttonType` is + `tab`) now respect explicitly set background color. - TabbedPane: Fixed `IndexOutOfBoundsException` when using tooltip text on close buttons and closing last/rightmost tab. (issue #235) - Extras: Added missing export of package diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatToggleButtonUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatToggleButtonUI.java index 22dedbdc..2d1a5f24 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatToggleButtonUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatToggleButtonUI.java @@ -146,10 +146,17 @@ public class FlatToggleButtonUI int height = c.getHeight(); int width = c.getWidth(); boolean selected = ((AbstractButton)c).isSelected(); + Color enabledColor = selected ? clientPropertyColor( c, TAB_BUTTON_SELECTED_BACKGROUND, tabSelectedBackground ) : null; + + // use component background if explicitly set + if( enabledColor == null ) { + Color bg = c.getBackground(); + if( isCustomBackground( bg ) ) + enabledColor = bg; + } // paint background - Color background = buttonStateColor( c, - selected ? clientPropertyColor( c, TAB_BUTTON_SELECTED_BACKGROUND, tabSelectedBackground ) : null, + Color background = buttonStateColor( c, enabledColor, null, tabFocusBackground, tabHoverBackground, null ); if( background != null ) { g.setColor( background );