Browse Source

Unwrap border before checking if it is a VisualPaddingProvider.

pull/222/head
weisj 4 years ago
parent
commit
9da0638170
  1. 3
      core/src/main/java/com/github/weisj/darklaf/ui/VisualPaddingProvider.java
  2. 9
      core/src/main/java/com/github/weisj/darklaf/util/DarkUIUtil.java

3
core/src/main/java/com/github/weisj/darklaf/ui/VisualPaddingProvider.java

@ -27,6 +27,7 @@ import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.plaf.InsetsUIResource;
import com.github.weisj.darklaf.util.DarkUIUtil;
import com.github.weisj.darklaf.util.PropertyUtil;
public interface VisualPaddingProvider {
@ -36,7 +37,7 @@ public interface VisualPaddingProvider {
Insets getVisualPaddings(Component component);
static void updateProperty(final JComponent c) {
Border b = c.getBorder();
Border b = DarkUIUtil.getUnwrappedBorder(c);
if (b instanceof VisualPaddingProvider) {
Insets ins = ((VisualPaddingProvider) b).getVisualPaddings(c);
PropertyUtil.installProperty(c, VISUAL_PADDING_PROP,

9
core/src/main/java/com/github/weisj/darklaf/util/DarkUIUtil.java

@ -35,6 +35,7 @@ import java.util.function.Predicate;
import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.border.CompoundBorder;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.InsetsUIResource;
import javax.swing.table.TableCellEditor;
@ -60,6 +61,14 @@ public final class DarkUIUtil {
private static final Rectangle iconRect = new Rectangle();
private static final Rectangle textRect = new Rectangle();
public static Border getUnwrappedBorder(final JComponent c) {
Border b = c.getBorder();
while (b instanceof CompoundBorder) {
b = ((CompoundBorder) b).getOutsideBorder();
}
return b;
}
public static Rectangle applyInsets(final Rectangle rect, final Insets insets) {
if (insets != null && rect != null) {
rect.x += insets.left;

Loading…
Cancel
Save