public static Frame getTopFrame(Container c)
    {
        if (c instanceof Frame) 
            return (Frame)c;

        Container theFrame = c;
        do {
            theFrame = theFrame.getParent();
        } while ((theFrame != null) && !(theFrame instanceof Frame));
        
        if (theFrame == null) 
            theFrame = new Frame();

        return (Frame)theFrame;
    }