Here you can find the source of isFocused(Component component)
public static boolean isFocused(Component component)
//package com.java2s; /*/*from w w w .j a v a 2 s.co m*/ * @(#)QuaquaUtilities.java * * Copyright (c) 2003-2013 Werner Randelshofer, Switzerland. * You may not use, copy or modify this file, except in compliance with the * accompanying license terms. */ import java.awt.*; import javax.swing.*; public class Main { /** * Returns true, if the specified component is focus owner or permanent * focus owner and if the component is on an the active window. */ public static boolean isFocused(Component component) { // When a component is used as a cell renderer, the focus can // not be determined from the component itself. if (component instanceof JComponent) { if (((JComponent) component) .getClientProperty("Quaqua.Component.cellRendererFor") != null) { component = (Component) ((JComponent) component) .getClientProperty("Quaqua.Component.cellRendererFor"); } } KeyboardFocusManager m = KeyboardFocusManager .getCurrentKeyboardFocusManager(); Component c = m.getPermanentFocusOwner(); if (c == component) { Window ancestor = SwingUtilities.getWindowAncestor(component); return ancestor != null && ancestor.isFocused(); } else { return false; } } }