Here you can find the source of addMouseListenerToAll(Component parent, MouseListener listener)
public static void addMouseListenerToAll(Component parent, MouseListener listener)
//package com.java2s; //License from project: Open Source License import java.awt.Component; import java.awt.Container; import java.awt.event.MouseListener; import javax.swing.AbstractButton; import javax.swing.JComponent; public class Main { public static void addMouseListenerToAll(Component parent, MouseListener listener) { if (parent instanceof AbstractButton) { AbstractButton a = (AbstractButton) parent; boolean is = false; MouseListener[] kl = a.getMouseListeners(); for (MouseListener k : kl) { if (k.equals(listener)) { is = true;//w w w . jav a 2 s . c o m break; } } if (!is) a.addMouseListener(listener); } else if (parent instanceof JComponent) { JComponent a = (JComponent) parent; boolean is = false; MouseListener[] kl = a.getMouseListeners(); for (MouseListener k : kl) { if (k.equals(listener)) { is = true; break; } } if (!is) a.addMouseListener(listener); } if (parent instanceof Container) { Component[] comps = ((Container) parent).getComponents(); for (Component c : comps) { addMouseListenerToAll(c, listener); } } } }