Here you can find the source of isActive(JComponent c)
public static boolean isActive(JComponent c)
//package com.java2s; /*/*w w w .j a va 2 s . c o m*/ * Copyright 2005 MH-Software-Entwicklung. All rights reserved. * Use is subject to license terms. */ import java.lang.reflect.*; import java.awt.*; import javax.swing.*; public class Main { private static Double javaVersion = null; public static boolean isActive(JComponent c) { if (c == null) { return false; } boolean active = true; if (c instanceof JInternalFrame) { active = ((JInternalFrame) c).isSelected(); } if (active) { Container parent = c.getParent(); while (parent != null) { if (parent instanceof JInternalFrame) { active = ((JInternalFrame) parent).isSelected(); break; } parent = parent.getParent(); } } if (active) { active = isFrameActive(c); } return active; } public static boolean isFrameActive(JComponent c) { if (c == null) { return false; } if (c.getTopLevelAncestor() instanceof Window) { return isWindowActive((Window) c.getTopLevelAncestor()); } return true; } public static boolean isWindowActive(Window window) { if (getJavaVersion() >= 1.4) { try { Class paramTypes[] = null; Object args[] = null; Method m = window.getClass().getMethod("isActive", paramTypes); Boolean b = (Boolean) m.invoke(window, args); return b.booleanValue(); } catch (Exception ex) { } } return true; } public static double getJavaVersion() { if (javaVersion == null) { try { String ver = System.getProperties().getProperty( "java.version"); String version = ""; boolean firstPoint = true; for (int i = 0; i < ver.length(); i++) { if (ver.charAt(i) == '.') { if (firstPoint) { version += ver.charAt(i); } firstPoint = false; } else if (Character.isDigit(ver.charAt(i))) { version += ver.charAt(i); } } javaVersion = new Double(version); } catch (Exception ex) { javaVersion = new Double(1.3); } } return javaVersion.doubleValue(); } }