List of usage examples for javax.swing JComponent addHierarchyListener
public void addHierarchyListener(HierarchyListener l)
From source file:Main.java
public static void onShown(final JComponent component, final Runnable action) { component.addHierarchyListener(new HierarchyListener() { public void hierarchyChanged(final HierarchyEvent e) { if (e.getComponent() == component && (e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) > 0) { if (component.isShowing()) action.run();//www . ja v a 2 s .com } } }); }