static A bindToComponent(final A component, final Runnable onShow, final Runnable onUnShow) { swing { final Var flag = new(false); component.addAncestorListener(new AncestorListener { public void ancestorAdded(AncestorEvent event) { if (flag!) print("Warning: bindToComponent logic failure"); flag.set(true); pcallF(onShow); } public void ancestorRemoved(AncestorEvent event) { if (!flag!) print("Warning: bindToComponent logic failure"); flag.set(false); pcallF(onUnShow); } public void ancestorMoved(AncestorEvent event) { } }); if (component.isShowing()) { // Hopefully this matches the AncestorListener logic flag.set(true); pcallF(onShow); } } ret component; } static A bindToComponent(A component, Runnable onShow) { ret bindToComponent(component, onShow, null); }