Java JFrame Parent getRootFrame(Component c)

Here you can find the source of getRootFrame(Component c)

Description

Get the root frame of any component

License

Open Source License

Parameter

Parameter Description
c a parameter

Return

the top level frame sau un frame phony

Declaration

public static Frame getRootFrame(Component c) 

Method Source Code


//package com.java2s;
/*//from w w  w  . ja  v  a2 s  .c  om
 *
 * This file is part of Genome Artist.
 *
 * Genome Artist is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Genome Artist is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Genome Artist.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

import java.awt.Component;
import java.awt.Dialog;

import java.awt.Frame;
import java.awt.Window;

import javax.swing.SwingUtilities;

public class Main {
    private static Frame PHONY_FRAME = null;

    /**
     * Get the root frame of any component
     * @param c
     * @return the top level frame sau un frame phony
     */
    public static Frame getRootFrame(Component c) {
        if (c != null) {
            Window window = SwingUtilities.getWindowAncestor(c);
            if (window instanceof Frame) {
                return (Frame) window;
            } else if (window instanceof Dialog) {
                Dialog dialog = (Dialog) window;
                return getRootFrame(dialog.getOwner());
            }
        }

        //Valoare default
        return getPhonyFrame();
    }

    /**
     * Initialize un phony frame lazy
     * @return 
     */
    private static Frame getPhonyFrame() {
        if (PHONY_FRAME == null) {
            PHONY_FRAME = new Frame("phony");
        }

        //Phony frame
        return PHONY_FRAME;
    }
}

Related

  1. getParentFrameForCompomponent(Component comp)
  2. getParentInternalFrame(Component comp)
  3. getRealFrameParent(Component c)
  4. getRootFrame()
  5. getRootFrame(Component aComp)
  6. getRootFrame(java.awt.Component c)
  7. getRootFrame(JComponent component)
  8. getSpssInstallationDirectory(Frame parent)
  9. installOperation(final RootPaneContainer frame, final int condition, final KeyStroke keyStroke, final String actionKey, Action action)