From 7ebc1b27c17aa3ad68c8660cf08736aac4bb6216 Mon Sep 17 00:00:00 2001 From: daWoife Date: Sat, 15 Nov 2025 11:37:18 +0100 Subject: [PATCH] Update FlatRadioButtonUI.java The method applyStyleProperty of class FlatRadioButtonUI currently styles the variable icon, a field of the parent class BasicRadioButtonUI and the default icon which is set with UIManager.getIcon in method installDefaults. So the wrong icon is styled if someone subclasses FlatRadioBoxIcon or FlatCheckBoxIcon and sets this as the new icon for a JRadioButton or JCheckBox instance. (An example why someone would do so is shown in issue #413). With this change styling takes account of the current icon of a JRadioButton or JCheckBox. --- .../java/com/formdev/flatlaf/ui/FlatRadioButtonUI.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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 73706178..5c9bbf88 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 @@ -203,10 +203,15 @@ public class FlatRadioButtonUI protected Object applyStyleProperty( AbstractButton b, String key, Object value ) { // style icon if( key.startsWith( "icon." ) ) { - if( !(icon instanceof FlatCheckBoxIcon) ) + Icon styleIcon = b.getIcon(); + + if (styleIcon == null) + styleIcon = icon; + + if( !(styleIcon instanceof FlatCheckBoxIcon) ) return new UnknownStyleException( key ); - if( iconShared ) { + if( styleIcon == icon && iconShared ) { icon = FlatStylingSupport.cloneIcon( icon ); iconShared = false; }