code: public static Window getWindow(Component component) {
  
          if (component == null) {
              return null;
          } else if (component instanceof Window) {
              return (Window)component;
          } else {
              return getWindow(component.getParent());
          }
  
      }
docs: Gets the window which contains a given component.<p>
  
  @param component the component
  @return the window containing the component, or null if no component is found