From 3b16fc65a738ca6d4ba951f7530c7cf04c2687eb Mon Sep 17 00:00:00 2001 From: weisj Date: Sat, 27 Jun 2020 23:30:08 +0200 Subject: [PATCH] Avoid installing listeners on popup menus that don't need them. --- .../darklaf/ui/popupmenu/PopupMenuContainer.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/popupmenu/PopupMenuContainer.java b/core/src/main/java/com/github/weisj/darklaf/ui/popupmenu/PopupMenuContainer.java index c4a24b2e..07e69e6d 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/popupmenu/PopupMenuContainer.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/popupmenu/PopupMenuContainer.java @@ -109,13 +109,16 @@ public class PopupMenuContainer extends JPanel { return menuListener; } + protected void uninstallListeners() { + if (this.popupMenu != null) { + this.popupMenu.removeMenuKeyListener(menuKeyListener); + this.popupMenu.removePopupMenuListener(menuListener); + } + } + public void setPopupMenu(final JPopupMenu popupMenu) { MenuKeyListener keyListener = getMenuKeyListener(); PopupMenuListener popupMenuListener = getMenuListener(); - if (this.popupMenu != null) { - this.popupMenu.removeMenuKeyListener(keyListener); - this.popupMenu.removePopupMenuListener(popupMenuListener); - } this.popupMenu = popupMenu; if (popupMenu != null) { popupMenu.removeMenuKeyListener(keyListener); @@ -126,14 +129,15 @@ public class PopupMenuContainer extends JPanel { } public Popup createPopup(final JPopupMenu popupMenu, final int posX, final int posY, final int maxHeight) { - setPopupMenu(popupMenu); final Dimension prefSize = popupMenu.getPreferredSize(); + uninstallListeners(); if (maxHeight <= 0 || prefSize.height <= maxHeight) { setBounds(0, 0, prefSize.width, prefSize.height); popupMenu.setBorderPainted(true); return PopupFactory.getSharedInstance().getPopup(popupMenu.getInvoker(), popupMenu, posX, posY); } else { initComponents(); + setPopupMenu(popupMenu); int increment = 1; if (popupMenu.getComponentCount() > 0) { increment = Math.max(1, popupMenu.getComponent(0).getPreferredSize().height / 2);