code: public static void installWeakWindowFocusListener(JComponent component, WindowFocusListener focusListener) {
          WindowListener   weakFocusListener = createWeakWindowFocusListener(focusListener);
          AncestorListener ancestorListener  = createAncestorListener(component, weakFocusListener);
  
          component.addAncestorListener(ancestorListener);
      }
docs: Installs a {@link WindowFocusListener} on the given {@link JComponent}'s
  parent {@link Window}. If the {@code JComponent} doesn't yet have a
  parent, then the listener will be installed when the component is added
  to a container.
  
  @param component     the component who's parent frame to listen to focus
  changes on.
  @param focusListener the {@code WindowFocusListener} to notify when focus
  changes.