void (JComponent component) { Component[] children = component.getComponents(); component.setVisible(ContainerUtil.exists(children, it -> it.isVisible())); for (var child : children) { UIUtil.runWhenVisibilityChanged(child, () -> component.setVisible(ContainerUtil.exists(children, it -> it.isVisible()))); } }