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