void (boolean movable) { myMovable = movable; if (!myMovable && myMoveListener != null) { final MyContentPanel saved = myContent; ListenerUtil.removeMouseListener(saved, myMoveListener); ListenerUtil.removeMouseMotionListener(saved, myMoveListener); myMoveListener = null; } if (myCaption != null && myMovable) { final WindowMoveListener moveListener = new WindowMoveListener(myCaption) { @Override public void mousePressed(final MouseEvent e) { if (e.isConsumed()) return; if (UIUtil.isCloseClick(e) && myCaption.isWithinPanel(e)) { cancel(); } else { super.mousePressed(e); } } }; moveListener.installTo(myCaption); final MyContentPanel saved = myContent; Disposer.register(this, () -> { ListenerUtil.removeMouseListener(saved, moveListener); ListenerUtil.removeMouseMotionListener(saved, moveListener); }); myMoveListener = moveListener; } }