Java JFrame getParentJFrame(Container theFrame)

Here you can find the source of getParentJFrame(Container theFrame)

Description

finds a parent JFrame for the specified container.

License

Open Source License

Parameter

Parameter Description
theFrame the container whose parent is sought

Return

the parent JFrame of the container

Declaration

public static JFrame getParentJFrame(Container theFrame) 

Method Source Code

//package com.java2s;
// This software is licensed under the GNU General Public License,

import java.awt.Container;

import javax.swing.JFrame;

public class Main {
    /**// w w w  .j av  a2  s . c o m
     * finds a parent JFrame for the specified container. If none is found it invents one. Useful for creating new
     * dialogs that insist on having a parent
     * 
     * @param theFrame
     *           the container whose parent is sought
     * @return the parent JFrame of the container
     */
    public static JFrame getParentJFrame(Container theFrame) {
        do {
            theFrame = theFrame.getParent();
        } while ((theFrame != null) && !(theFrame instanceof JFrame));
        if (theFrame == null)
            theFrame = new JFrame();
        return (JFrame) theFrame;
    }
}

Related

  1. getJFrame(JPanel panel, String title, int width, int height)
  2. getJFrame(Window window)
  3. getJFrameOfComponent(Component cmpnt)
  4. getModalDlg(JFrame frame, String title)
  5. getParentJFrame(Component c)
  6. getParentJFrame(java.awt.Container component)
  7. getPersistentExtendedStateMask(JFrame frame)
  8. getRootJFrame(Component c)
  9. getRootJFrame(Component component)