Java tutorial
//package com.java2s; /** * some swing helpers from * http://www.javapractices.com/topic/TopicAction.do?Id=152 * * @author Hirondelle Systems (code snippets used on BSD license) */ import java.awt.Component; import java.awt.Container; import java.awt.event.MouseListener; public class Main { /** * adds the mouse listener to the component and all its children. This is * useful when you want to catch events on the ends of a scroll bar. * * @param comp * a GUI component (e.g., a scroll bar) * @param listener * a mouse listener */ public static void registerWithAllChildren(Component comp, MouseListener listener) { comp.addMouseListener(listener); if (comp instanceof Container) for (Component child : ((Container) comp).getComponents()) registerWithAllChildren(child, listener); } }