Use this method to determine whether a particular component has the focus
import javax.swing.JFrame; public class Main { public static void main() { JFrame f = new JFrame(); boolean b = f.isFocusOwner(); } }