Example usage for java.awt Container isAncestorOf

List of usage examples for java.awt Container isAncestorOf

Introduction

In this page you can find the example usage for java.awt Container isAncestorOf.

Prototype

public boolean isAncestorOf(Component c) 

Source Link

Document

Checks if the component is contained in the component hierarchy of this container.

Usage

From source file:StackLayout.java

/**
 * Set the currently displayed component.  If passed null for the component,
 * all contained components will be made invisible (sliding windows do this)
 * @param c Component to show//from  w w w .ja v a 2 s. com
 * @param parent Parent container
 */
public void showComponent(Component c, Container parent) {
    Component comp = getVisibleComponent();
    if (comp != c) {
        if (!parent.isAncestorOf(c) && c != null) {
            parent.add(c);
        }
        synchronized (parent.getTreeLock()) {
            if (comp != null) {
                comp.setVisible(false);
            }
            visibleComp = new WeakReference<Component>(c);
            if (c != null) {
                c.setVisible(true);
            }
            // trigger re-layout
            if (c instanceof JComponent) {
                ((JComponent) c).revalidate();
            } else {
                parent.validate(); //XXX revalidate should work!
            }
        }
    }
}