Here you can find the source of getRootFrame(Component aComp)
public static JFrame getRootFrame(Component aComp)
//package com.java2s; //License from project: Apache License import java.awt.Component; import javax.swing.JFrame; public class Main { public static JFrame getRootFrame(Component aComp) { Component lParent = aComp; while (lParent != null && !(lParent instanceof JFrame)) { lParent = lParent.getParent(); }// w ww . j a v a 2 s . c om if (lParent != null && lParent instanceof JFrame) { return (JFrame) lParent; } return null; } }