code: public static Window getWindowForComponent(Component component) throws HeadlessException
  	{
  		if (component == null)
  		{
  			return JOptionPane.getRootFrame();
  		}
  		if (component instanceof Frame || component instanceof Dialog)
  		{
  			return (Window)component;
  		}
  		return getWindowForComponent(component.getParent());
  	}
docs: Gets the toplevel <code>Frame</code> or <code>Dialog</code>
  
  @param component
  the parent component
  @return the the toplevel <code>Frame</code> or <code>Dialog</code>
  @throws HeadlessException
  if <code>GraphicsEnvironment.isHeadless</code> returns <code>true</code>
  @see java.awt.GraphicsEnvironment#isHeadless