Here you can find the source of getRoot(JComponent pchildComponent)
public static JDialog getRoot(JComponent pchildComponent)
//package com.java2s; //License from project: Open Source License import java.awt.Container; import javax.swing.JComponent; import javax.swing.JDialog; public class Main { public static JDialog getRoot(JComponent pchildComponent) { Container objParent = pchildComponent.getParent(); while (objParent != null) { objParent = objParent.getParent(); if (objParent instanceof JDialog) { return (JDialog) objParent; }//from w ww.ja v a2s . co m } return null; } }