* java/awt/GridLayout.java (layoutContainer): Use tree lock.
authortromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 10 Nov 2002 23:11:21 +0000 (23:11 +0000)
committertromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 10 Nov 2002 23:11:21 +0000 (23:11 +0000)
(getSize): Likewise.
* java/awt/FlowLayout.java (layoutContainer): Use tree lock.
(getSize): Likewise.
* java/awt/BorderLayout.java (layoutContainer): Use tree lock.
(calcSize): Likewise.
* java/awt/CardLayout.java (getSize): Use tree lock.
(gotoComponent): Likewise.
(layoutContainer): Likewise.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@58998 138bc75d-0d04-0410-961f-82ee72b054a4

libjava/ChangeLog
libjava/java/awt/BorderLayout.java
libjava/java/awt/CardLayout.java
libjava/java/awt/FlowLayout.java
libjava/java/awt/GridLayout.java

index a05b2cd..1cb7dde 100644 (file)
@@ -1,5 +1,15 @@
 2002-11-10  Tom Tromey  <tromey@redhat.com>
 
+       * java/awt/GridLayout.java (layoutContainer): Use tree lock.
+       (getSize): Likewise.
+       * java/awt/FlowLayout.java (layoutContainer): Use tree lock.
+       (getSize): Likewise.
+       * java/awt/BorderLayout.java (layoutContainer): Use tree lock.
+       (calcSize): Likewise.
+       * java/awt/CardLayout.java (getSize): Use tree lock.
+       (gotoComponent): Likewise.
+       (layoutContainer): Likewise.
+
        * java/io/natFileDescriptorWin32.cc (read): Handle case where
        count is 0.
        * java/io/natFileDescriptorPosix.cc (read): Handle case where
index d1bbd1f..930773f 100644 (file)
@@ -529,80 +529,83 @@ invalidateLayout(Container parent)
 public void
 layoutContainer(Container target)
 {
-  Insets i = target.getInsets();
-
-  ComponentOrientation orient = target.getComponentOrientation ();
-  boolean left_to_right = orient.isLeftToRight ();
-
-  Component my_north = north;
-  Component my_east = east;
-  Component my_south = south;
-  Component my_west = west;
-
-  // Note that we currently don't handle vertical layouts.  Neither
-  // does JDK 1.3.
-  if (firstLine != null)
-    my_north = firstLine;
-  if (lastLine != null)
-    my_south = lastLine;
-  if (firstItem != null)
+  synchronized (target.getTreeLock ())
     {
-      if (left_to_right)
-       my_west = firstItem;
-      else
-       my_east = firstItem;
+      Insets i = target.getInsets();
+
+      ComponentOrientation orient = target.getComponentOrientation ();
+      boolean left_to_right = orient.isLeftToRight ();
+
+      Component my_north = north;
+      Component my_east = east;
+      Component my_south = south;
+      Component my_west = west;
+
+      // Note that we currently don't handle vertical layouts.  Neither
+      // does JDK 1.3.
+      if (firstLine != null)
+       my_north = firstLine;
+      if (lastLine != null)
+       my_south = lastLine;
+      if (firstItem != null)
+       {
+         if (left_to_right)
+           my_west = firstItem;
+         else
+           my_east = firstItem;
+       }
+      if (lastItem != null)
+       {
+         if (left_to_right)
+           my_east = lastItem;
+         else
+           my_west = lastItem;
+       }
+
+      Dimension c = calcCompSize(center, PREF);
+      Dimension n = calcCompSize(my_north, PREF);
+      Dimension s = calcCompSize(my_south, PREF);
+      Dimension e = calcCompSize(my_east, PREF);
+      Dimension w = calcCompSize(my_west, PREF);
+      Dimension t = target.getSize();
+
+      /*
+       <-> hgap     <-> hgap
+       +----------------------------+          }
+       |t                           |          } i.top
+       |  +----------------------+  |  --- y1  }
+       |  |n                     |  |
+       |  +----------------------+  |          } vgap
+       |  +---+ +----------+ +---+  |  --- y2  }        }
+       |  |w  | |c         | |e  |  |                   } hh
+       |  +---+ +----------+ +---+  |          } vgap   }
+       |  +----------------------+  |  --- y3  }
+       |  |s                     |  |
+       |  +----------------------+  |          }
+       |                            |          } i.bottom
+       +----------------------------+          }
+       |x1   |x2          |x3
+       <---------------------->
+       <-->         ww           <-->
+       i.left                    i.right
+      */
+
+      int x1 = i.left;
+      int x2 = x1 + w.width + hgap;
+      int x3 = t.width - i.right - e.width;
+      int ww = t.width - i.right - i.left;
+
+      int y1 = i.top;
+      int y2 = y1 + n.height + vgap;
+      int y3 = t.height - i.bottom - s.height;
+      int hh = y3-y2-vgap;
+
+      setBounds(center, x2, y2, x3-x2-hgap, hh);
+      setBounds(my_north, x1, y1, ww, n.height);
+      setBounds(my_south, x1, y3, ww, s.height);
+      setBounds(my_west, x1, y2, w.width, hh);
+      setBounds(my_east, x3, y2, e.width, hh);
     }
-  if (lastItem != null)
-    {
-      if (left_to_right)
-       my_east = lastItem;
-      else
-       my_west = lastItem;
-    }
-
-  Dimension c = calcCompSize(center, PREF);
-  Dimension n = calcCompSize(my_north, PREF);
-  Dimension s = calcCompSize(my_south, PREF);
-  Dimension e = calcCompSize(my_east, PREF);
-  Dimension w = calcCompSize(my_west, PREF);
-  Dimension t = target.getSize();
-
-    /*
-             <-> hgap     <-> hgap
-      +----------------------------+          }
-      |t                           |          } i.top
-      |  +----------------------+  |  --- y1  }
-      |  |n                     |  |
-      |  +----------------------+  |          } vgap
-      |  +---+ +----------+ +---+  |  --- y2  }        }
-      |  |w  | |c         | |e  |  |                   } hh
-      |  +---+ +----------+ +---+  |          } vgap   }
-      |  +----------------------+  |  --- y3  }
-      |  |s                     |  |
-      |  +----------------------+  |          }
-      |                            |          } i.bottom
-      +----------------------------+          }
-         |x1   |x2          |x3
-         <---------------------->
-      <-->         ww           <-->
-     i.left                    i.right
-    */
-
-  int x1 = i.left;
-  int x2 = x1 + w.width + hgap;
-  int x3 = t.width - i.right - e.width;
-  int ww = t.width - i.right - i.left;
-
-  int y1 = i.top;
-  int y2 = y1 + n.height + vgap;
-  int y3 = t.height - i.bottom - s.height;
-  int hh = y3-y2-vgap;
-
-  setBounds(center, x2, y2, x3-x2-hgap, hh);
-  setBounds(my_north, x1, y1, ww, n.height);
-  setBounds(my_south, x1, y3, ww, s.height);
-  setBounds(my_west, x1, y2, w.width, hh);
-  setBounds(my_east, x3, y2, e.width, hh);
 }
 
 /*************************************************************************/
@@ -648,59 +651,62 @@ calcCompSize(Component comp, int what)
 private Dimension
 calcSize(Container target, int what)
 {
-  Insets ins = target.getInsets();
-
-  ComponentOrientation orient = target.getComponentOrientation ();
-  boolean left_to_right = orient.isLeftToRight ();
-
-  Component my_north = north;
-  Component my_east = east;
-  Component my_south = south;
-  Component my_west = west;
-
-  // Note that we currently don't handle vertical layouts.  Neither
-  // does JDK 1.3.
-  if (firstLine != null)
-    my_north = firstLine;
-  if (lastLine != null)
-    my_south = lastLine;
-  if (firstItem != null)
+  synchronized (target.getTreeLock ())
     {
-      if (left_to_right)
-       my_west = firstItem;
-      else
-       my_east = firstItem;
-    }
-  if (lastItem != null)
-    {
-      if (left_to_right)
-       my_east = lastItem;
-      else
-       my_west = lastItem;
-    }
+      Insets ins = target.getInsets();
+
+      ComponentOrientation orient = target.getComponentOrientation ();
+      boolean left_to_right = orient.isLeftToRight ();
+
+      Component my_north = north;
+      Component my_east = east;
+      Component my_south = south;
+      Component my_west = west;
+
+      // Note that we currently don't handle vertical layouts.  Neither
+      // does JDK 1.3.
+      if (firstLine != null)
+       my_north = firstLine;
+      if (lastLine != null)
+       my_south = lastLine;
+      if (firstItem != null)
+       {
+         if (left_to_right)
+           my_west = firstItem;
+         else
+           my_east = firstItem;
+       }
+      if (lastItem != null)
+       {
+         if (left_to_right)
+           my_east = lastItem;
+         else
+           my_west = lastItem;
+       }
       
-  Dimension ndim = calcCompSize(my_north, what);
-  Dimension sdim = calcCompSize(my_south, what);
-  Dimension edim = calcCompSize(my_east, what);
-  Dimension wdim = calcCompSize(my_west, what);
-  Dimension cdim = calcCompSize(center, what);
+      Dimension ndim = calcCompSize(my_north, what);
+      Dimension sdim = calcCompSize(my_south, what);
+      Dimension edim = calcCompSize(my_east, what);
+      Dimension wdim = calcCompSize(my_west, what);
+      Dimension cdim = calcCompSize(center, what);
 
-  int width = edim.width + cdim.width + wdim.width + (hgap * 2);
-  if (ndim.width > width)
-    width = ndim.width;
-  if (sdim.width > width)
-    width = sdim.width;
+      int width = edim.width + cdim.width + wdim.width + (hgap * 2);
+      if (ndim.width > width)
+       width = ndim.width;
+      if (sdim.width > width)
+       width = sdim.width;
 
-  width += (ins.left + ins.right);
+      width += (ins.left + ins.right);
 
-  int height = edim.height;
-  if (cdim.height > height)
-    height = cdim.height;
-  if (wdim.height > height)
-    height = wdim.height;
+      int height = edim.height;
+      if (cdim.height > height)
+       height = cdim.height;
+      if (wdim.height > height)
+       height = wdim.height;
 
-  height += (ndim.height + sdim.height + (vgap * 2) + ins.top + ins.bottom);
+      height += (ndim.height + sdim.height + (vgap * 2) + ins.top + ins.bottom);
 
-  return(new Dimension(width, height));
+      return(new Dimension(width, height));
+    }
 }
 } // class BorderLayout 
index 38eb91e..10ffa2e 100644 (file)
@@ -165,21 +165,24 @@ public class CardLayout implements LayoutManager2, Serializable
    */ 
   public void layoutContainer (Container parent)
   {
-    int width = parent.width;
-    int height = parent.height;
+    synchronized (parent.getTreeLock ())
+      {
+       int width = parent.width;
+       int height = parent.height;
 
-    Insets ins = parent.getInsets ();
+       Insets ins = parent.getInsets ();
 
-    int num = parent.ncomponents;
-    Component[] comps = parent.component;
+       int num = parent.ncomponents;
+       Component[] comps = parent.component;
 
-    int x = ins.left + hgap;
-    int y = ins.top + vgap;
-    width = width - 2 * hgap - ins.left - ins.right;
-    height = height - 2 * vgap - ins.top - ins.bottom;
+       int x = ins.left + hgap;
+       int y = ins.top + vgap;
+       width = width - 2 * hgap - ins.left - ins.right;
+       height = height - 2 * vgap - ins.top - ins.bottom;
 
-    for (int i = 0; i < num; ++i)
-      comps[i].setBounds (x, y, width, height);
+       for (int i = 0; i < num; ++i)
+         comps[i].setBounds (x, y, width, height);
+      }
   }
 
   /** Get the maximum layout size of the container.
@@ -287,91 +290,97 @@ public class CardLayout implements LayoutManager2, Serializable
   private void gotoComponent (Container parent, int what,
                              Component target)
   {
-    int num = parent.ncomponents;
-    // This is more efficient than calling getComponents().
-    Component[] comps = parent.component;
-    int choice = -1;
-
-    if (what == FIRST)
-      choice = 0;
-    else if (what == LAST)
-      choice = num - 1;
-    else if (what >= 0)
-      choice = what;
-
-    for (int i = 0; i < num; ++i)
+    synchronized (parent.getTreeLock ())
       {
-       // If TARGET is set then we are looking for a specific
-       // component.
-       if (target != null)
-         {
-           if (target == comps[i])
-             choice = i;
-         }
-
-       if (comps[i].isVisible ())
+       int num = parent.ncomponents;
+       // This is more efficient than calling getComponents().
+       Component[] comps = parent.component;
+       int choice = -1;
+
+       if (what == FIRST)
+         choice = 0;
+       else if (what == LAST)
+         choice = num - 1;
+       else if (what >= 0)
+         choice = what;
+
+       for (int i = 0; i < num; ++i)
          {
-           if (what == NEXT)
+           // If TARGET is set then we are looking for a specific
+           // component.
+           if (target != null)
              {
-               choice = i + 1;
-               if (choice == num)
-                 choice = 0;
+               if (target == comps[i])
+                 choice = i;
              }
-           else if (what == PREV)
-             {
-               choice = i - 1;
-               if (choice < 0)
-                 choice = num - 1;
-             }
-           else if (choice == i)
+
+           if (comps[i].isVisible ())
              {
-               // Do nothing if we're already looking at the right
-               // component.
-               return;
+               if (what == NEXT)
+                 {
+                   choice = i + 1;
+                   if (choice == num)
+                     choice = 0;
+                 }
+               else if (what == PREV)
+                 {
+                   choice = i - 1;
+                   if (choice < 0)
+                     choice = num - 1;
+                 }
+               else if (choice == i)
+                 {
+                   // Do nothing if we're already looking at the right
+                   // component.
+                   return;
+                 }
+               comps[i].setVisible (false);
+
+               if (choice >= 0)
+                 break;
              }
-           comps[i].setVisible (false);
-
-           if (choice >= 0)
-             break;
          }
-      }
 
-    if (choice >= 0 && choice < num)
-      comps[choice].setVisible (true);
+       if (choice >= 0 && choice < num)
+         comps[choice].setVisible (true);
+      }
   }
 
   // Compute the size according to WHAT.
   private Dimension getSize (Container parent, int what)
   {
-    int w = 0, h = 0, num = parent.ncomponents;
-    Component[] comps = parent.component;
-
-    for (int i = 0; i < num; ++i)
+    synchronized (parent.getTreeLock ())
       {
-       Dimension d;
+       int w = 0, h = 0, num = parent.ncomponents;
+       Component[] comps = parent.component;
+
+       for (int i = 0; i < num; ++i)
+         {
+           Dimension d;
 
-       if (what == MIN)
-         d = comps[i].getMinimumSize ();
-       else if (what == MAX)
-         d = comps[i].getMaximumSize ();
-       else
-         d = comps[i].getPreferredSize ();
+           if (what == MIN)
+             d = comps[i].getMinimumSize ();
+           else if (what == MAX)
+             d = comps[i].getMaximumSize ();
+           else
+             d = comps[i].getPreferredSize ();
 
-       w = Math.max (d.width, w);
-       h = Math.max (d.height, h);
-      }
+           w = Math.max (d.width, w);
+           h = Math.max (d.height, h);
+         }
 
-    Insets i = parent.getInsets ();
-    w += 2 * hgap + i.right + i.left;
-    h += 2 * vgap + i.bottom + i.top;
+       Insets i = parent.getInsets ();
+       w += 2 * hgap + i.right + i.left;
+       h += 2 * vgap + i.bottom + i.top;
 
-    // Handle overflow.
-    if (w < 0)
-      w = Integer.MAX_VALUE;
-    if (h < 0)
-      h = Integer.MAX_VALUE;
+       // Handle overflow.
+       if (w < 0)
+         w = Integer.MAX_VALUE;
+       if (h < 0)
+         h = Integer.MAX_VALUE;
 
-    return new Dimension (w, h);
+       return new Dimension (w, h);
+      }
   }
 
   /**
index e328d63..1f9465e 100644 (file)
@@ -150,76 +150,79 @@ public class FlowLayout implements LayoutManager, Serializable
    */
   public void layoutContainer (Container parent)
   {
-    int num = parent.getComponentCount ();
-    // This is more efficient than calling getComponents().
-    Component[] comps = parent.component;
+    synchronized (parent.getTreeLock ())
+      {
+       int num = parent.getComponentCount ();
+       // This is more efficient than calling getComponents().
+       Component[] comps = parent.component;
 
-    Dimension d = parent.getSize ();
-    Insets ins = parent.getInsets ();
+       Dimension d = parent.getSize ();
+       Insets ins = parent.getInsets ();
 
-    ComponentOrientation orient = parent.getComponentOrientation ();
-    boolean left_to_right = orient.isLeftToRight ();
+       ComponentOrientation orient = parent.getComponentOrientation ();
+       boolean left_to_right = orient.isLeftToRight ();
 
-    int y = ins.top + vgap;
-    int i = 0;
-    while (i < num)
-      {
-       // Find the components which go in the current row.
-       int new_w = ins.left + hgap + ins.right;
-       int new_h = 0;
-       int j;
-       boolean found_one = false;
-       for (j = i; j < num && ! found_one; ++j)
+       int y = ins.top + vgap;
+       int i = 0;
+       while (i < num)
          {
-           // Skip invisible items.
-           if (! comps[i].visible)
-             continue;
-
-           Dimension c = comps[i].getPreferredSize ();
-
-           int next_w = new_w + hgap + c.width;
-           if (next_w <= d.width || ! found_one)
+           // Find the components which go in the current row.
+           int new_w = ins.left + hgap + ins.right;
+           int new_h = 0;
+           int j;
+           boolean found_one = false;
+           for (j = i; j < num && ! found_one; ++j)
              {
-               new_w = next_w;
-               new_h = Math.max (new_h, c.height);
-               found_one = true;
+               // Skip invisible items.
+               if (! comps[i].visible)
+                 continue;
+
+               Dimension c = comps[i].getPreferredSize ();
+
+               int next_w = new_w + hgap + c.width;
+               if (next_w <= d.width || ! found_one)
+                 {
+                   new_w = next_w;
+                   new_h = Math.max (new_h, c.height);
+                   found_one = true;
+                 }
+               else
+                 {
+                   // Must start a new row, and we already found an item
+                   break;
+                 }
              }
-           else
-             {
-               // Must start a new row, and we already found an item
-               break;
-             }
-         }
 
-       // Set the location of each component for this row.
-       int x;
+           // Set the location of each component for this row.
+           int x;
 
-       int myalign = align;
-       if (align == LEADING)
-         myalign = left_to_right ? LEFT : RIGHT;
-       else if (align == TRAILING)
-         myalign = left_to_right ? RIGHT : LEFT;
+           int myalign = align;
+           if (align == LEADING)
+             myalign = left_to_right ? LEFT : RIGHT;
+           else if (align == TRAILING)
+             myalign = left_to_right ? RIGHT : LEFT;
 
-       if (myalign == LEFT)
-         x = ins.left + hgap;
-       else if (myalign == CENTER)
-         x = (d.width - new_w) / 2;
-       else
-         x = d.width - new_w;
+           if (myalign == LEFT)
+             x = ins.left + hgap;
+           else if (myalign == CENTER)
+             x = (d.width - new_w) / 2;
+           else
+             x = d.width - new_w;
 
-       for (int k = i; k < j; ++k)
-         {
-           if (comps[k].visible)
+           for (int k = i; k < j; ++k)
              {
-               Dimension c = comps[k].getPreferredSize ();
-               comps[k].setBounds (x, y, c.width, new_h);
-               x += c.width + hgap;
+               if (comps[k].visible)
+                 {
+                   Dimension c = comps[k].getPreferredSize ();
+                   comps[k].setBounds (x, y, c.width, new_h);
+                   x += c.width + hgap;
+                 }
              }
-         }
 
-       // Advance to next row.
-       i = j;
-       y += new_h + vgap;
+           // Advance to next row.
+           i = j;
+           y += new_h + vgap;
+         }
       }
   }
 
@@ -304,36 +307,39 @@ public class FlowLayout implements LayoutManager, Serializable
   // This method is used to compute the various sizes.
   private Dimension getSize (Container parent, boolean is_min)
   {
-    int w, h, num = parent.getComponentCount ();
-    // This is more efficient than calling getComponents().
-    Component[] comps = parent.component;
-
-    w = 0;
-    h = 0;
-    for (int i = 0; i < num; ++i)
+    synchronized (parent.getTreeLock ())
       {
-       if (! comps[i].visible)
-         continue;
+       int w, h, num = parent.getComponentCount ();
+       // This is more efficient than calling getComponents().
+       Component[] comps = parent.component;
 
-       // FIXME: can we just directly read the fields in Component?
-       // Or will that not work with subclassing?
-       Dimension d;
+       w = 0;
+       h = 0;
+       for (int i = 0; i < num; ++i)
+         {
+           if (! comps[i].visible)
+             continue;
 
-       if (is_min)
-         d = comps[i].getMinimumSize ();
-       else
-         d = comps[i].getPreferredSize ();
+           // FIXME: can we just directly read the fields in Component?
+           // Or will that not work with subclassing?
+           Dimension d;
 
-       w += d.width;
-       h = Math.max (d.height, h);
-      }
+           if (is_min)
+             d = comps[i].getMinimumSize ();
+           else
+             d = comps[i].getPreferredSize ();
 
-    Insets ins = parent.getInsets ();
+           w += d.width;
+           h = Math.max (d.height, h);
+         }
 
-    w += (num + 1) * hgap + ins.left + ins.right;
-    h += 2 * vgap + ins.top + ins.bottom;
+       Insets ins = parent.getInsets ();
 
-    return new Dimension (w, h);
+       w += (num + 1) * hgap + ins.left + ins.right;
+       h += 2 * vgap + ins.top + ins.bottom;
+
+       return new Dimension (w, h);
+      }
   }
 
   /**
index 51e012a..a8befc4 100644 (file)
@@ -153,62 +153,65 @@ public class GridLayout implements LayoutManager, Serializable
    */
   public void layoutContainer (Container parent)
   {
-    int num = parent.ncomponents;
-
-    // There's no point, and handling this would mean adding special
-    // cases.
-    if (num == 0)
-      return;
-
-    // This is more efficient than calling getComponents().
-    Component[] comps = parent.component;
-
-    int real_rows = rows;
-    int real_cols = cols;
-    if (real_rows == 0)
-      real_rows = (num + real_cols - 1) / real_cols;
-    else
-      real_cols = (num + real_rows - 1) / real_rows;
-
-    // We might have less than a single row.  In this case we expand
-    // to fill.
-    if (num < real_cols)
-      real_cols = num;
-
-    Dimension d = parent.getSize ();
-    Insets ins = parent.getInsets ();
-
-    // Compute width and height of each cell in the grid.
-    int tw = d.width - ins.left - ins.right;
-    tw = (tw - (real_cols - 1) * hgap) / real_cols;
-    int th = d.height - ins.top - ins.bottom;
-    th = (th - (real_rows - 1) * vgap) / real_rows;
-
-    // If the cells are too small, still try to do something.
-    if (tw < 0)
-      tw = 1;
-    if (th < 0)
-      th = 1;
-
-    int x = ins.left;
-    int y = ins.top;
-    int i = 0;
-    int recount = 0;
-
-    while (i < num)
+    synchronized (parent.getTreeLock ())
       {
-       comps[i].setBounds (x, y, tw, th);
+       int num = parent.ncomponents;
 
-       ++i;
-       ++recount;
-       if (recount == real_cols)
+       // There's no point, and handling this would mean adding special
+       // cases.
+       if (num == 0)
+         return;
+
+       // This is more efficient than calling getComponents().
+       Component[] comps = parent.component;
+
+       int real_rows = rows;
+       int real_cols = cols;
+       if (real_rows == 0)
+         real_rows = (num + real_cols - 1) / real_cols;
+       else
+         real_cols = (num + real_rows - 1) / real_rows;
+
+       // We might have less than a single row.  In this case we expand
+       // to fill.
+       if (num < real_cols)
+         real_cols = num;
+
+       Dimension d = parent.getSize ();
+       Insets ins = parent.getInsets ();
+
+       // Compute width and height of each cell in the grid.
+       int tw = d.width - ins.left - ins.right;
+       tw = (tw - (real_cols - 1) * hgap) / real_cols;
+       int th = d.height - ins.top - ins.bottom;
+       th = (th - (real_rows - 1) * vgap) / real_rows;
+
+       // If the cells are too small, still try to do something.
+       if (tw < 0)
+         tw = 1;
+       if (th < 0)
+         th = 1;
+
+       int x = ins.left;
+       int y = ins.top;
+       int i = 0;
+       int recount = 0;
+
+       while (i < num)
          {
-           recount = 0;
-           y += vgap + th;
-           x = ins.left;
+           comps[i].setBounds (x, y, tw, th);
+
+           ++i;
+           ++recount;
+           if (recount == real_cols)
+             {
+               recount = 0;
+               y += vgap + th;
+               x = ins.left;
+             }
+           else
+             x += hgap + tw;
          }
-       else
-         x += hgap + tw;
       }
   }
 
@@ -301,36 +304,39 @@ public class GridLayout implements LayoutManager, Serializable
   // This method is used to compute the various sizes.
   private Dimension getSize (Container parent, boolean is_min)
   {
-    int w = 0, h = 0, num = parent.ncomponents;
-    // This is more efficient than calling getComponents().
-    Component[] comps = parent.component;
-
-    for (int i = 0; i < num; ++i)
+    synchronized (parent.getTreeLock ())
       {
-       Dimension d;
+       int w = 0, h = 0, num = parent.ncomponents;
+       // This is more efficient than calling getComponents().
+       Component[] comps = parent.component;
 
-       if (is_min)
-         d = comps[i].getMinimumSize ();
-       else
-         d = comps[i].getPreferredSize ();
+       for (int i = 0; i < num; ++i)
+         {
+           Dimension d;
 
-       w = Math.max (d.width, w);
-       h = Math.max (d.height, h);
-      }
+           if (is_min)
+             d = comps[i].getMinimumSize ();
+           else
+             d = comps[i].getPreferredSize ();
+
+           w = Math.max (d.width, w);
+           h = Math.max (d.height, h);
+         }
 
-    int real_rows = rows;
-    int real_cols = cols;
-    if (real_rows == 0)
-      real_rows = (num + real_cols - 1) / real_cols;
-    else
-      real_cols = (num + real_rows - 1) / real_rows;
-
-    Insets ins = parent.getInsets ();
-    // We subtract out an extra gap here because the gaps are only
-    // between cells.
-    w = ins.left + ins.right + real_cols * (w + hgap) - hgap;
-    h = ins.top + ins.bottom + real_rows * (h + vgap) - vgap;
-    return new Dimension (w, h);
+       int real_rows = rows;
+       int real_cols = cols;
+       if (real_rows == 0)
+         real_rows = (num + real_cols - 1) / real_cols;
+       else
+         real_cols = (num + real_rows - 1) / real_rows;
+
+       Insets ins = parent.getInsets ();
+       // We subtract out an extra gap here because the gaps are only
+       // between cells.
+       w = ins.left + ins.right + real_cols * (w + hgap) - hgap;
+       h = ins.top + ins.bottom + real_rows * (h + vgap) - vgap;
+       return new Dimension (w, h);
+      }
   }
 
   /**