code: private void installWindowListeners(JRootPane root, Component parent) {
          if (parent instanceof Window) {
              window = (Window) parent;
          } else {
              window = SwingUtilities.getWindowAncestor(parent);
          }
  
          if (window != null) {
              if (mouseInputListener == null) {
                  mouseInputListener = createWindowMouseInputListener(root);
              }
  
              window.addMouseListener(mouseInputListener);
              window.addMouseMotionListener(mouseInputListener);
              if (windowListener == null) {
                  windowListener = createFocusListener();
                  window.addWindowListener(windowListener);
              }
          }
      }
docs: Installs the necessary Listeners on the parent <code>Window</code>, if
  there is one.
  
  <p>This takes the parent so that cleanup can be done from <code>
  removeNotify</code>, at which point the parent hasn't been reset yet.</p>
  
  @param root   the JRootPane.
  @param parent The parent of the JRootPane