private void installDisposeListeners() {
    myKeyEventDispatcher = e -> {
      dispose();
      return false;
    };
    myKeyboardFocusManager.addKeyEventDispatcher(myKeyEventDispatcher);

    myMulticastListener = new AWTEventListener() {
      @Override
      public void eventDispatched(AWTEvent event) {
        if (event.getID() == MouseEvent.MOUSE_PRESSED) {
          dispose();
        }
      }
    };

    Toolkit.getDefaultToolkit().addAWTEventListener(myMulticastListener, AWTEvent.MOUSE_EVENT_MASK );

    myComponentListener = new ComponentListener() {
      @Override
      public void componentHidden(ComponentEvent e) {
        dispose();
      }

      @Override
      public void componentMoved(ComponentEvent e) {
        dispose();
      }

      @Override
      public void componentResized(ComponentEvent e) {
        dispose();
      }

      @Override
      public void componentShown(ComponentEvent e) {
        dispose();
      }
    };

    myWindowListener = new WindowListener() {
      @Override
      public void windowActivated(WindowEvent e) {
        dispose();
      }

      @Override
      public void windowClosed(WindowEvent e) {
        dispose();
      }

      @Override
      public void windowClosing(WindowEvent e) {
        dispose();
      }

      @Override
      public void windowDeactivated(WindowEvent e) {
        dispose();
      }

      @Override
      public void windowDeiconified(WindowEvent e) {
        dispose();
      }

      @Override
      public void windowIconified(WindowEvent e) {
        dispose();
      }

      @Override
      public void windowOpened(WindowEvent e) {
        dispose();
      }
    };
    myTargetWindow.addWindowListener(myWindowListener);

    myWindowStateListener = new WindowStateListener() {
      @Override
      public void windowStateChanged(WindowEvent e) {
        dispose();
      }
    };
    myTargetWindow.addWindowStateListener(myWindowStateListener);
  }
private void installDisposeListeners()