Java JFrame getJFrameOfComponent(Component cmpnt)

Here you can find the source of getJFrameOfComponent(Component cmpnt)

Description

get J Frame Of Component

License

Open Source License

Declaration

public static JFrame getJFrameOfComponent(Component cmpnt) 

Method Source Code


//package com.java2s;
/* //from ww w  .  j  av  a 2s .c o  m
 * The MIT License
 *
 * Copyright 2014 Kamnev Georgiy (nt.gocha@gmail.com).
 *
 * ??????? ????????? ?????????, ????????????, ?????, ?????????? ????? ??????? ???????????? 
 * ????????????? ? ??????????????? ???????????? (? ?????????? ?????????? "??????????? ????????????"), 
 * ????????????? ??????????? ???????????? ??? ???????????, ???????? ?????????????? ????? ?? 
 * ??????????????, ???????????, ?????????, ???????????, ??????????, ?????????????????, ?????????????????? 
 * ?/??? ??????? ????? ???????????? ?????????????, ????? ??? ? ?????, ??????? ??????????????????? 
 * ?????? ??????????? ????????????, ??? ??????????? ?????????? ????????:
 *
 * ??????????????? ???????? ? ?????? ????????? ?????? ???? ???????? ?? ???? ????? 
 * ??? ???????? ?????? ??????? ???????????? ?????????????.
 *
 * ????????? ????????????? ???????????? ???????????????? ????? ?????, ??? ?????? ????? ???????????, 
 * ????? ????????????? ??? ?????????????????, ????????, ??? ??? ???????????????? ????????????? ?????????? ????????????, 
 * ???????????? ?? ??? ????????????? ??????????????? ? ??????????????? ?????. ??? ? ?????? ??????? ??????? 
 * ??? ?????????????????? ??? ?????? ????????????????? ?? ?????? ? ??????????? ???????, ??????? 
 * ??? ?????? ???????????? ?? ??????????? ?????????????, ????????? ??? ??????, ?????????? ??, ??????? 
 * ????????? ??? ???????????? ? ????????????? ????????????? ??? ???????????????? ?????????????? ???????????? 
 * ??? ?????? ?????????? ? ????????????? ?????????????.
 */

import java.awt.Component;
import java.awt.Container;

import javax.swing.JFrame;

public class Main {

    public static JFrame getJFrameOfComponent(Component cmpnt) {
        if (cmpnt == null) {
            throw new IllegalArgumentException("cmpnt == null");
        }

        Container cntr = cmpnt.getParent();
        while (true) {
            if (cntr == null)
                break;
            if (cntr instanceof JFrame)
                break;

            cntr = cntr.getParent();
        }

        if (cntr instanceof JFrame)
            return (JFrame) cntr;
        return null;
    }
}

Related

  1. getFileSelection(JFrame parent, boolean onlyDirectories, String startingDir)
  2. getJFrame(Component cmp)
  3. getjFrame(int width, int height)
  4. getJFrame(JPanel panel, String title, int width, int height)
  5. getJFrame(Window window)
  6. getModalDlg(JFrame frame, String title)
  7. getParentJFrame(Component c)
  8. getParentJFrame(Container theFrame)
  9. getParentJFrame(java.awt.Container component)