if (parentComponent == null) return null; if (parentComponent instanceof Frame) return (Frame) parentComponent; Frame parent = null; while (parentComponent.getParent() != null) { parentComponent = parentComponent.getParent(); if (parentComponent instanceof Frame) { parent = (Frame) parentComponent; break; } } return parent;
return (Frame) SwingUtilities.getAncestorOfClass(Frame.class, parentComponent);
  public static Frame getFrameForComponent(Component parentComponent)  {    if (parentComponent == null)      return null;    if (parentComponent instanceof Frame)      return (Frame) parentComponent;    Frame parent = null;    while (parentComponent.getParent() != null)    {	parentComponent = parentComponent.getParent();	if (parentComponent instanceof Frame)	  {	    parent = (Frame) parentComponent;	    break;	  }      }    return parent;    }