From 760384d9ee6b225b4463df69756795cf4c27754a Mon Sep 17 00:00:00 2001 From: weisj Date: Sun, 8 Mar 2020 21:42:11 +0100 Subject: [PATCH] Fixed NPE in ScrollLayoutManager when changing theme. --- .../darklaf/ui/scrollpane/DarkScrollPaneUI.java | 13 +++++++++++++ .../ui/scrollpane/ScrollLayoutManagerDelegate.java | 5 +++++ 2 files changed, 18 insertions(+) diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/scrollpane/DarkScrollPaneUI.java b/core/src/main/java/com/github/weisj/darklaf/ui/scrollpane/DarkScrollPaneUI.java index ed240764..92d55a6a 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/scrollpane/DarkScrollPaneUI.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/scrollpane/DarkScrollPaneUI.java @@ -126,8 +126,21 @@ public class DarkScrollPaneUI extends BasicScrollPaneUI { public void installUI(final JComponent x) { super.installUI(x); oldLayout = (ScrollPaneLayout) x.getLayout(); + if (oldLayout instanceof ScrollLayoutManagerDelegate) { + oldLayout = ((ScrollLayoutManagerDelegate) oldLayout).getDelegate(); + } if (oldLayout != null) { x.setLayout(new ScrollLayoutManagerDelegate(oldLayout) { + + @Override + public void addLayoutComponent(final String name, final Component comp) { + if (name != null && name.toUpperCase().endsWith("CORNER")) { + Component oldComp = getDelegate().getCorner(name); + getDelegate().removeLayoutComponent(oldComp); + } + super.addLayoutComponent(name, comp); + } + @Override public void layoutContainer(final Container parent) { super.layoutContainer(parent); diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/scrollpane/ScrollLayoutManagerDelegate.java b/core/src/main/java/com/github/weisj/darklaf/ui/scrollpane/ScrollLayoutManagerDelegate.java index 33e8ce7b..755632d4 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/scrollpane/ScrollLayoutManagerDelegate.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/scrollpane/ScrollLayoutManagerDelegate.java @@ -49,6 +49,11 @@ public class ScrollLayoutManagerDelegate extends ScrollPaneLayout { delegate.addLayoutComponent(name, comp); } + @Override + public void syncWithScrollPane(final JScrollPane sp) { + delegate.syncWithScrollPane(sp); + } + @Override public void removeLayoutComponent(final Component comp) { delegate.removeLayoutComponent(comp);