static A bindToComponent(final A component, final Runnable onShow, final Runnable onUnShow) { swing { component.addAncestorListener(new AncestorListener { public void ancestorAdded(AncestorEvent event) { pcallF(onShow); } public void ancestorRemoved(AncestorEvent event) { pcallF(onUnShow); } public void ancestorMoved(AncestorEvent event) { } }); if (c.isShowing()) // Hopefully this matches the AncestorListener logic pcallF(onShow); } ret component; } static A bindToComponent(A component, Runnable onShow) { ret bindToComponent(component, onShow, null); }