get Active Top Level Frame - Java Swing

Java examples for Swing:JFrame

Description

get Active Top Level Frame

Demo Code

/*/*  w w w. ja v  a2s.  c  om*/
 * @(#)GeneralUtil.java   1.13 10/03/24
 * 
 * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
 * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
//package com.java2s;

public class Main {
    public static Frame getActiveTopLevelFrame() {
        Frame[] frames = Frame.getFrames();
        int index = -1;
        if (frames == null)
            return null;
        for (int i = 0; i < frames.length; i++) {
            if (frames[i].getFocusOwner() != null) {
                index = i;
            }
        }
        return (index >= 0 ? frames[index] : null);
    }
}

Related Tutorials