void (@NotNull JBPopup popup, @NotNull JComponent component) { var listener = new PopupDragListener(popup); component.addMouseListener(listener); component.addMouseMotionListener(listener); Disposer.register(popup, () -> { component.removeMouseMotionListener(listener); component.removeMouseListener(listener); }); }