Example usage for java.awt Component getMouseMotionListeners

List of usage examples for java.awt Component getMouseMotionListeners

Introduction

In this page you can find the example usage for java.awt Component getMouseMotionListeners.

Prototype

public synchronized MouseMotionListener[] getMouseMotionListeners() 

Source Link

Document

Returns an array of all the mouse motion listeners registered on this component.

Usage

From source file:Main.java

/**
 * Inserts the mouse motion listener at the particular index in the listeners' chain.
 *
 * @param component//  w  ww . j  a  v a 2s.c o m
 * @param l
 * @param index
 */
public static void insertMouseMotionListener(Component component, MouseMotionListener l, int index) {
    MouseMotionListener[] listeners = component.getMouseMotionListeners();

    for (MouseMotionListener listener : listeners) {
        component.removeMouseMotionListener(listener);
    }

    for (int i = 0; i < listeners.length; i++) {
        MouseMotionListener listener = listeners[i];

        if (index == i) {
            component.addMouseMotionListener(l);
        }

        component.addMouseMotionListener(listener);
    }

    // inex is too large, add to the end.
    if (index > listeners.length - 1) {
        component.addMouseMotionListener(l);
    }
}

From source file:edu.ku.brc.ui.UIHelper.java

/**
 * Removes the Mouse Listeners.// w w  w.  j  a  v  a  2 s  . co  m
 * @param c component
 */
public static void removeMouseListeners(final Component c) {
    if (c != null) {
        for (MouseListener l : c.getMouseListeners()) {
            c.removeMouseListener(l);
        }
        for (MouseMotionListener l : c.getMouseMotionListeners()) {
            c.removeMouseMotionListener(l);
        }
    }
}