Java JFrame Parent getParentInternalFrame(Component comp)

Here you can find the source of getParentInternalFrame(Component comp)

Description

Tries to determine the internal frame this component is part of.

License

Open Source License

Parameter

Parameter Description
comp the component to start with

Return

the parent internal frame if one exists or null if not

Declaration

public static JInternalFrame getParentInternalFrame(Component comp) 

Method Source Code

//package com.java2s;
/*/*from  www . j  a  va2  s  . c o m*/
 *   This program 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.
 *
 *   This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import javax.swing.JInternalFrame;
import java.awt.Component;
import java.awt.Container;

public class Main {
    /**
     * Tries to determine the internal frame this container is part of.
     *
     * @param cont   the container to start with
     * @return      the parent internal frame if one exists or null if not
     */
    public static JInternalFrame getParentInternalFrame(Container cont) {
        return (JInternalFrame) getParent(cont, JInternalFrame.class);
    }

    /**
     * Tries to determine the internal frame this component is part of.
     *
     * @param comp   the component to start with
     * @return      the parent internal frame if one exists or null if not
     */
    public static JInternalFrame getParentInternalFrame(Component comp) {
        if (comp instanceof Container)
            return (JInternalFrame) getParent((Container) comp, JInternalFrame.class);
        else
            return null;
    }

    /**
     * Tries to determine the parent this panel is part of.
     *
     * @param cont   the container to get the parent for
     * @param parentClass   the class of the parent to obtain
     * @return      the parent if one exists or null if not
     */
    public static Object getParent(Container cont, Class parentClass) {
        Container result;
        Container parent;

        result = null;

        parent = cont;
        while (parent != null) {
            if (parentClass.isInstance(parent)) {
                result = parent;
                break;
            } else {
                parent = parent.getParent();
            }
        }

        return result;
    }
}

Related

  1. getParentFrame(Frame[] parentFrames)
  2. getParentFrame(JComponent c)
  3. getParentFrame(JComponent comp)
  4. getParentFrame(JComponent comp)
  5. getParentFrameForCompomponent(Component comp)
  6. getRealFrameParent(Component c)
  7. getRootFrame()
  8. getRootFrame(Component aComp)
  9. getRootFrame(Component c)