From 162a6c6b1375a568e92201702b0f474476987102 Mon Sep 17 00:00:00 2001 From: weisj Date: Fri, 10 Jul 2020 19:54:56 +0200 Subject: [PATCH] Fixed NPE when showing tree cell popup and no cell is targeted. Fixes #194 --- .../ui/cell/hint/CellHintPopupListener.java | 42 ++++++++++--------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/cell/hint/CellHintPopupListener.java b/core/src/main/java/com/github/weisj/darklaf/ui/cell/hint/CellHintPopupListener.java index 1d8a476c..e1062bbf 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/cell/hint/CellHintPopupListener.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/cell/hint/CellHintPopupListener.java @@ -90,29 +90,31 @@ public class CellHintPopupListener extends MouseInputAd final boolean isEditing = cellContainer.isEditingCell(index); final Rectangle allocation = cellContainer.getAllocation(); final Rectangle cellBounds = cellContainer.getCellBoundsAt(index, isEditing); - final Rectangle visibleBounds = allocation.intersection(cellBounds); - if (visibleBounds.contains(p)) { - final Component comp = cellContainer.getEffectiveCellRendererComponent(index, isEditing); - final Dimension prefSize = isEditing - ? comp.getBounds().getSize() - : comp.getPreferredSize(); - if (!(visibleBounds.width >= prefSize.width && visibleBounds.height >= prefSize.height)) { - Point popupLocation = cellContainer.getComponent().getLocationOnScreen(); - Rectangle rect = calculatePopupBounds(cellBounds, visibleBounds, !isEditing); - if (!visibleBounds.contains(rect)) { - cellBounds.x = rect.x - cellBounds.x; - cellBounds.y = rect.y - cellBounds.y; - rect.x += popupLocation.x; - rect.y += popupLocation.y; - enter(index, rect, cellBounds); - return; - } else { - lastIndex = index; + if (cellBounds != null && allocation != null) { + final Rectangle visibleBounds = allocation.intersection(cellBounds); + if (visibleBounds.contains(p)) { + final Component comp = cellContainer.getEffectiveCellRendererComponent(index, isEditing); + final Dimension prefSize = isEditing + ? comp.getBounds().getSize() + : comp.getPreferredSize(); + if (!(visibleBounds.width >= prefSize.width && visibleBounds.height >= prefSize.height)) { + Point popupLocation = cellContainer.getComponent().getLocationOnScreen(); + Rectangle rect = calculatePopupBounds(cellBounds, visibleBounds, !isEditing); + if (!visibleBounds.contains(rect)) { + cellBounds.x = rect.x - cellBounds.x; + cellBounds.y = rect.y - cellBounds.y; + rect.x += popupLocation.x; + rect.y += popupLocation.y; + enter(index, rect, cellBounds); + return; + } else { + lastIndex = index; + } } + return; } - } else { - lastIndex = null; } + lastIndex = null; leave(); }