Example usage for java.awt Container removeComponentListener

List of usage examples for java.awt Container removeComponentListener

Introduction

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

Prototype

public synchronized void removeComponentListener(ComponentListener l) 

Source Link

Document

Removes the specified component listener so that it no longer receives component events from this component.

Usage

From source file:Main.java

/**
 * Destroys container by destroying its childs structure and removing all
 * listeners./*from  w  ww. ja v a2s  .  c o m*/
 *
 * @param container
 *            container to destroy
 */
public static void destroyContainer(final Container container) {
    for (final Container toDestroy : collectAllContainers(container)) {
        toDestroy.removeAll();
        toDestroy.setLayout(null);

        for (final MouseListener listener : toDestroy.getMouseListeners()) {
            toDestroy.removeMouseListener(listener);
        }
        for (final MouseMotionListener listener : toDestroy.getMouseMotionListeners()) {
            toDestroy.removeMouseMotionListener(listener);
        }
        for (final MouseWheelListener listener : toDestroy.getMouseWheelListeners()) {
            toDestroy.removeMouseWheelListener(listener);
        }
        for (final KeyListener listener : toDestroy.getKeyListeners()) {
            toDestroy.removeKeyListener(listener);
        }
        for (final ComponentListener listener : toDestroy.getComponentListeners()) {
            toDestroy.removeComponentListener(listener);
        }
        for (final ContainerListener listener : toDestroy.getContainerListeners()) {
            toDestroy.removeContainerListener(listener);
        }
        if (toDestroy instanceof JComponent) {
            final JComponent jComponent = (JComponent) toDestroy;
            for (final AncestorListener listener : jComponent.getAncestorListeners()) {
                jComponent.removeAncestorListener(listener);
            }
        }
    }
}