Java JFrame getRootJFrame(Component c)

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

Description

This is the only method that relies on Swing.

License

Open Source License

Parameter

Parameter Description
c a Component

Return

the JFrame containing the component or null if the component doesn't have a containing JFrame.

Declaration

public static javax.swing.JFrame getRootJFrame(Component c) 

Method Source Code


//package com.java2s;

import java.awt.*;

public class Main {
    /**//from  w w w .  j  a  va2s  .c o m
     * This is the only method that relies on Swing.  Comment this one out and
     * this class is AWT-only capable.
     *
     * @param c  a Component
     * @return   the JFrame containing the component or null if the component
     * doesn't have a containing JFrame.
     */
    public static javax.swing.JFrame getRootJFrame(Component c) {
        Object parent = c.getParent();
        while (parent != null) {
            if (parent instanceof javax.swing.JFrame)
                return (javax.swing.JFrame) parent;
            parent = ((Component) parent).getParent();
        }
        return null;
    }
}

Related

  1. getModalDlg(JFrame frame, String title)
  2. getParentJFrame(Component c)
  3. getParentJFrame(Container theFrame)
  4. getParentJFrame(java.awt.Container component)
  5. getPersistentExtendedStateMask(JFrame frame)
  6. getRootJFrame(Component component)
  7. getTheJFrame(String title, int width, int height, int x, int y)
  8. getTopJFrame(Container c)
  9. getUserInput(JFrame _frame, String arg1, String arg2, Object arg3)