Here you can find the source of getParentJFrame(java.awt.Container component)
protected static JFrame getParentJFrame(java.awt.Container component)
//package com.java2s; import javax.swing.JFrame; public class Main { protected static JFrame getParentJFrame(java.awt.Container component) { while (component != null) { if (component.getClass().toString().equals("class javax.swing.JFrame") || component.getClass().getSuperclass().toString().equals("class javax.swing.JFrame")) { return (JFrame) component; }/*from w w w. ja v a2 s .c o m*/ component = component.getParent(); } return null; } }