From b59813a48b9a35e69a1a076b1e1c1f1694340c17 Mon Sep 17 00:00:00 2001 From: Jannis Weis <31143295+weisJ@users.noreply.github.com> Date: Thu, 27 Apr 2023 22:15:51 +0200 Subject: [PATCH] Icons: Inherit visual padding from icons in StateIcon --- .../darklaf/properties/icons/StateIcon.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/property-loader/src/main/java/com/github/weisj/darklaf/properties/icons/StateIcon.java b/property-loader/src/main/java/com/github/weisj/darklaf/properties/icons/StateIcon.java index 789539bd..0b453c38 100644 --- a/property-loader/src/main/java/com/github/weisj/darklaf/properties/icons/StateIcon.java +++ b/property-loader/src/main/java/com/github/weisj/darklaf/properties/icons/StateIcon.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2019-2021 Jannis Weis + * Copyright (c) 2019-2023 Jannis Weis * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and * associated documentation files (the "Software"), to deal in the Software without restriction, @@ -25,8 +25,12 @@ import java.util.List; import javax.swing.*; +import org.jetbrains.annotations.NotNull; + +import com.github.weisj.swingdsl.visualpadding.VisualPaddingProvider; + /** Icon that should be used with JCheckBox or JRadioButton. All icons should have the same size. */ -public class StateIcon implements Icon { +public class StateIcon implements Icon, VisualPaddingProvider { private final Icon icon; private final Icon disabledIcon; @@ -87,4 +91,13 @@ public class StateIcon implements Icon { public int getIconHeight() { return icon.getIconHeight(); } + + @Override + public @NotNull Insets getVisualPaddings(@NotNull Component component) { + Icon icon = getIcon(component); + if (icon instanceof VisualPaddingProvider) { + return ((VisualPaddingProvider) icon).getVisualPaddings(component); + } + return new Insets(0, 0, 0, 0); + } }