From dd8ab242fb93c0d9107cd75fc8258b85a17beb5b Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Tue, 19 Jan 2021 19:13:20 +0100 Subject: [PATCH] CheckBox and RadioButton: fill component background as soon as background color is different to default background color, even if component is not opaque (which is the default). This paints selection if using the component as cell renderer a Table, Tree or List (better fix for #77) --- CHANGELOG.md | 10 ++++++++++ .../java/com/formdev/flatlaf/ui/FlatRadioButtonUI.java | 7 +++++-- .../main/java/com/formdev/flatlaf/ui/FlatTableUI.java | 8 -------- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 32c5bd0a..5dc5cc4b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,16 @@ FlatLaf Change Log ================== +## 1.0-rc2-SNAPSHOT + +#### Fixed bugs + +- CheckBox and RadioButton: Fill component background as soon as background + color is different to default background color, even if component is not + opaque (which is the default). This paints selection if using the component as + cell renderer a Table, Tree or List. + + ## 1.0-rc1 #### New features and improvements diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatRadioButtonUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatRadioButtonUI.java index e1329a9c..8d508988 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatRadioButtonUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatRadioButtonUI.java @@ -27,7 +27,6 @@ import javax.swing.JComponent; import javax.swing.LookAndFeel; import javax.swing.UIManager; import javax.swing.plaf.ComponentUI; -import javax.swing.plaf.UIResource; import javax.swing.plaf.basic.BasicRadioButtonUI; import com.formdev.flatlaf.icons.FlatCheckBoxIcon; import com.formdev.flatlaf.util.UIScale; @@ -58,6 +57,8 @@ public class FlatRadioButtonUI protected int iconTextGap; protected Color disabledText; + private Color defaultBackground; + private boolean defaults_initialized = false; public static ComponentUI createUI( JComponent c ) { @@ -74,6 +75,8 @@ public class FlatRadioButtonUI iconTextGap = FlatUIUtils.getUIInt( prefix + "iconTextGap", 4 ); disabledText = UIManager.getColor( prefix + "disabledText" ); + defaultBackground = UIManager.getColor( prefix + "background" ); + defaults_initialized = true; } @@ -120,7 +123,7 @@ public class FlatRadioButtonUI // - if background was explicitly set to a non-UIResource color if( !c.isOpaque() && ((AbstractButton)c).isContentAreaFilled() && - !(c.getBackground() instanceof UIResource) ) + (c.getBackground() != defaultBackground) ) { g.setColor( c.getBackground() ); g.fillRect( 0, 0, c.getWidth(), c.getHeight() ); diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTableUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTableUI.java index f436f195..385f7f1f 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTableUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTableUI.java @@ -25,7 +25,6 @@ import java.awt.Graphics2D; import java.awt.event.FocusEvent; import java.awt.event.FocusListener; import java.awt.geom.Rectangle2D; -import javax.swing.JCheckBox; import javax.swing.JComponent; import javax.swing.JScrollPane; import javax.swing.JViewport; @@ -34,7 +33,6 @@ import javax.swing.SwingUtilities; import javax.swing.UIManager; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicTableUI; -import javax.swing.table.TableCellRenderer; import com.formdev.flatlaf.util.Graphics2DProxy; import com.formdev.flatlaf.util.UIScale; @@ -137,12 +135,6 @@ public class FlatTableUI oldIntercellSpacing = table.getIntercellSpacing(); table.setIntercellSpacing( intercellSpacing ); } - - // checkbox is non-opaque in FlatLaf and therefore would not paint selection - // --> make checkbox renderer opaque (but opaque in Metal or Windows LaF) - TableCellRenderer booleanRenderer = table.getDefaultRenderer( Boolean.class ); - if( booleanRenderer instanceof JCheckBox ) - ((JCheckBox)booleanRenderer).setOpaque( true ); } @Override