public static void runWhenVisibilityChanged(@NotNull Component component, Runnable runnable) {
    component.addComponentListener(new ComponentAdapter() {
      @Override
      public void componentShown(ComponentEvent e) {
        runnable.run();
      }

      @Override
      public void componentHidden(ComponentEvent e) {
        runnable.run();
      }
    });
  }
public static void runWhenVisibilityChanged(@NotNull Component component, Runnable runnable)