src/share/classes/java/awt/Component.java

Print this page

        

@@ -2759,12 +2759,15 @@
     @Deprecated
     public void layout() {
     }
 
     /**
-     * Ensures that this component has a valid layout.  This method is
-     * primarily intended to operate on instances of <code>Container</code>.
+     * Validates this component.
+     * <p>
+     * The meaning of the term <i>validating</i> is defined by the ancestors of
+     * this class. See {@link Container#validate} for more details.
+     *
      * @see       #invalidate
      * @see       #doLayout()
      * @see       LayoutManager
      * @see       Container#validate
      * @since     JDK1.0

@@ -2789,16 +2792,27 @@
             }
         }
     }
 
     /**
-     * Invalidates this component.  This component and all parents
-     * above it are marked as needing to be laid out.  This method can
-     * be called often, so it needs to execute quickly.
+     * Invalidates this component and its ancestors.
+     * <p>
+     * All ancestors of this component up to the nearest validate root (or up
+     * to the root of the hierarchy if there's no a validate root container
+     * present) are marked invalid also.  Marking a container <i>invalid</i>
+     * indicates that the container needs to be laid out.
+     * <p>
+     * This method is called automatically when any layout-related information
+     * changes (e.g. setting the bounds of the component, or adding the
+     * component to a container).
+     * <p>
+     * This method can be called often, so it should work fast.
+     *
      * @see       #validate
      * @see       #doLayout
      * @see       LayoutManager
+     * @see       java.awt.Container#isValidateRoot
      * @since     JDK1.0
      */
     public void invalidate() {
         synchronized (getTreeLock()) {
             /* Nullify cached layout and size information.

@@ -2813,15 +2827,24 @@
                 minSize = null;
             }
             if (!isMaximumSizeSet()) {
                 maxSize = null;
             }
+            invalidateParent();
+        }
+    }
+
+    /**
+     * Invalidates the parent of this component if any.
+     *
+     * This method MUST BE invoked under the TreeLock.
+     */
+    void invalidateParent() {
             if (parent != null) {
                 parent.invalidateIfValid();
             }
         }
-    }
 
     /** Invalidates the component unless it is already invalid.
      */
     final void invalidateIfValid() {
         if (isValid()) {