Here you can find the source of getRootContainer(Component c)
public static Container getRootContainer(Component c)
//package com.java2s; /*// w w w . j a va 2 s.c om * Copyright (C) 2015 University of Oregon * * You may distribute under the terms of either the GNU General Public * License or the Apache License, as specified in the LICENSE file. * * For more information, see the LICENSE file. */ import java.awt.*; import javax.swing.*; public class Main { public static Container getRootContainer(Component c) { if (c == null) { return null; } Container parent = c.getParent(); while ((parent != null) && !(parent instanceof JPopupMenu) && !(parent instanceof JInternalFrame) && !(parent instanceof Window) && (parent.getParent() != null)) { parent = parent.getParent(); } return parent; } }