Index: user/src/com/google/gwt/user/client/ui/Panel.java
===================================================================
--- user/src/com/google/gwt/user/client/ui/Panel.java	(revision 1204)
+++ user/src/com/google/gwt/user/client/ui/Panel.java	(working copy)
@@ -71,29 +71,46 @@
       throw new IllegalArgumentException("w is not a child of this panel");
     }
 
-    // Remove it at the DOM and GWT levels.
+    // setParent() must be called before removeChild() to ensure that the
+    // element is still attached when onDetach()/onUnload() are called.
     Element elem = w.getElement();
     w.setParent(null);
     DOM.removeChild(DOM.getParent(elem), elem);
   }
 
   protected void onAttach() {
-    super.onAttach();
+    // Do all of the attach work except for calling onLoad(). This ensures that
+    // this panel is attached before its children.
+    doAttach();
 
     // Ensure that all child widgets are attached.
     for (Iterator it = iterator(); it.hasNext();) {
       Widget child = (Widget) it.next();
       child.onAttach();
     }
+
+    // Call onLoad *after* all of the panel's children are attached.
+    onLoad();
   }
 
   protected void onDetach() {
-    super.onDetach();
-
     // Ensure that all child widgets are detached.
     for (Iterator it = iterator(); it.hasNext();) {
       Widget child = (Widget) it.next();
       child.onDetach();
     }
+
+    // Call super.onDetach() last so that the children are detached before
+    // the parent.
+    super.onDetach();
   }
+
+  /**
+   * A Panel's onLoad method will be called only once all of its children are
+   * attached.
+   * 
+   * @see Widget#onLoad()
+   */
+  protected void onLoad() {
+  }
 }
Index: user/src/com/google/gwt/user/client/ui/Widget.java
===================================================================
--- user/src/com/google/gwt/user/client/ui/Widget.java	(revision 1204)
+++ user/src/com/google/gwt/user/client/ui/Widget.java	(working copy)
@@ -73,18 +73,27 @@
 
   /**
    * This method is called when a widget is attached to the browser's document.
-   * To receive notification after a Widget has been added from the
+   * To receive notification after a Widget has been added to the
    * document, override the {@link #onLoad} method.
    * 
    * <p>
    * Subclasses that override this method must call
    * <code>super.onAttach()</code> to ensure that the Widget has been
-   * attached to the underlying Element.
+   * attached to its underlying Element.
    * </p>
    * 
    * @throws IllegalStateException if this widget is already attached
    */
   protected void onAttach() {
+    doAttach();
+    onLoad();
+  }
+
+  /**
+   * Sets the widget's attached flag, and ensures that it is listening to events
+   * on its underlying element.
+   */
+  protected void doAttach() {
     if (attached) {
       throw new IllegalStateException(
           "Should only call onAttach when the widget is detached from the browser's document");
@@ -96,9 +105,6 @@
     // while the widget is attached, because it creates a circular
     // reference between JavaScript and the DOM.
     DOM.setEventListener(getElement(), this);
-
-    // Now that the widget is attached, call onLoad().
-    onLoad();
   }
 
   /**
@@ -110,7 +116,7 @@
    * Subclasses that override this method must call
    * <code>super.onDetach()</code> to ensure that the Widget has been
    * detached from the underlying Element.  Failure to do so will result
-   * in application memeroy leaks due to circular references between DOM
+   * in application memory leaks due to circular references between DOM
    * Elements and JavaScript objects.
    * </p>
    * 
@@ -121,13 +127,13 @@
       throw new IllegalStateException(
           "Should only call onDetach when the widget is attached to the browser's document");
     }
-    
+
     // Give the user a chance to clean up, but don't trust the code to not throw
     try {
       onUnload();
     } finally {
       attached = false;
-  
+
       // Clear out the element's event listener (breaking the circular
       // reference between it and the widget).
       DOM.setEventListener(getElement(), null);
@@ -140,7 +146,7 @@
    */
   protected void onLoad() {
   }
-  
+
   /**
    * This method is called immediately before a widget will be detached from the
    * browser's document.
