void (@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(); } }); }