Here you can find the source of getParentFrame(JComponent comp)
public static JFrame getParentFrame(JComponent comp)
//package com.java2s; // modify it under the terms of the GNU General Public License version 2 import javax.swing.*; import java.awt.*; public class Main { /**/*from ww w. j a v a2 s. c om*/ * Finds the parent frame of the component or null if there isn't one */ public static JFrame getParentFrame(JComponent comp) { Component p = comp.getParent(); while (p != null) { if (p instanceof JFrame) return (JFrame) p; else p = p.getParent(); } return null; } }