Example usage for javax.swing JComponent addHierarchyListener

List of usage examples for javax.swing JComponent addHierarchyListener

Introduction

In this page you can find the example usage for javax.swing JComponent addHierarchyListener.

Prototype

public void addHierarchyListener(HierarchyListener l) 

Source Link

Document

Adds the specified hierarchy listener to receive hierarchy changed events from this component when the hierarchy to which this container belongs changes.

Usage

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
            }
        }
    });
}