Java tutorial
//package com.java2s; import java.awt.Component; import java.awt.Container; public class Main { public static boolean hasOrContainsFocus(Component c) { if (c.hasFocus()) { return true; } if (c instanceof Container) { Container container = (Container) c; for (Component childComponent : container.getComponents()) { if (hasOrContainsFocus(childComponent)) { return true; } } } return false; } }