static A bindToComponent(A component, final Runnable onShow, final Runnable onUnShow) { component.addAncestorListener(new AncestorListener() { public void ancestorAdded(AncestorEvent event) { callF(onShow); } public void ancestorRemoved(AncestorEvent event) { callF(onUnShow); } public void ancestorMoved(AncestorEvent event) { } }); ret component; }