Here you can find the source of getParentJFrame(Component c)
public static JFrame getParentJFrame(Component c)
//package com.java2s; /******************************************************************************* * Copyright (c) 2016 Weasis Team and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors:/*from w w w. java 2 s . com*/ * Nicolas Roduit - initial API and implementation *******************************************************************************/ import java.awt.Component; import java.awt.Container; import javax.swing.JFrame; public class Main { public static JFrame getParentJFrame(Component c) { for (Container p = c.getParent(); p != null; p = p.getParent()) { if (p instanceof JFrame) { return (JFrame) p; } } return null; } }