Some of the problems I have had with Panels stemmed from BorderLayout.
Many things were not being painted because the size was set incorrectly.

This is now fixed.

2006-02-13  Lillian Angel  <[EMAIL PROTECTED]>

        * java/awt/BorderLayout.java
        (layoutContainer): Rewrote part of this function to
        properly set the bounds of the components.
        (setBounds): Removed method, not needed.

Index: java/awt/BorderLayout.java
===================================================================
RCS file: /sources/classpath/classpath/java/awt/BorderLayout.java,v
retrieving revision 1.22
diff -u -r1.22 BorderLayout.java
--- java/awt/BorderLayout.java	6 Dec 2005 16:30:03 -0000	1.22
+++ java/awt/BorderLayout.java	13 Feb 2006 17:27:22 -0000
@@ -460,27 +460,30 @@
   }
 
   /**
-   * Lays out the specified container according to the constraints
-   * in this object.
-   *
+   * Lays out the specified container according to the constraints in this
+   * object.
+   * 
    * @param target The container to lay out.
    */
   public void layoutContainer(Container target)
   {
-    synchronized (target.getTreeLock ())
+    synchronized (target.getTreeLock())
       {
         Insets i = target.getInsets();
+        int top = i.top;
+        int bottom = target.height - i.bottom;
+        int left = i.left;
+        int right = target.width - i.right;
 
-        ComponentOrientation orient = target.getComponentOrientation ();
-        boolean left_to_right = orient.isLeftToRight ();
+        boolean left_to_right = target.getComponentOrientation().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.
+        // FIXME: Note that we currently don't handle vertical layouts.
+        // Neither does JDK 1.3.
         if (firstLine != null)
           my_north = firstLine;
         if (lastLine != null)
@@ -500,65 +503,42 @@
               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);
-        int targetWidth = target.getWidth();
-        int targetHeight = target.getHeight();
-
-        /*
-	<-> 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 + (w.width == 0 ? 0 : hgap);
-        int x3;
-        if (targetWidth <= i.right + e.width)
-          x3 = x2 + w.width + (w.width == 0 ? 0 : hgap);
-        else
-          x3 = targetWidth - i.right - e.width;
-        int ww = targetWidth - i.right - i.left;
+        if (my_north != null)
+          {
+            Dimension n = calcCompSize(my_north, PREF);
+            my_north.setBounds(left, top, right - left, n.height);
+            top += n.height + vgap;
+          }
 
-        int y1 = i.top;
-        int y2 = y1 + n.height + (n.height == 0 ? 0 : vgap);
-        int midh = Math.max(e.height, Math.max(w.height, c.height));
-        int y3;
-        if (targetHeight <= i.bottom + s.height)
-          y3 = y2 + midh + vgap;
-        else
-          y3 = targetHeight - i.bottom - s.height;
-        int hh = y3-y2-(s.height == 0 ? 0 : vgap);
+        if (my_south != null)
+          {
+            Dimension s = calcCompSize(my_south, PREF);
+            my_south.setBounds(left, bottom - s.height, right - left, s.height);
+            bottom -= s.height + vgap;
+          }
 
-        setBounds(center, x2, y2, x3-x2-(w.width == 0 ? 0 : 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 (my_east != null)
+          {
+            Dimension e = calcCompSize(my_east, PREF);
+            my_east.setBounds(right - e.width, top, e.width, bottom - top);
+            right -= e.width + hgap;
+          }
+
+        if (my_west != null)
+          {
+            Dimension w = calcCompSize(my_west, PREF);
+            my_west.setBounds(left, top, w.width, bottom - top);
+            left += w.width + hgap;
+          }
+
+        if (center != null)
+          center.setBounds(left, top, right - left, bottom - top);
       }
   }
 
   /**
    * Returns a string representation of this layout manager.
-   *
+   * 
    * @return A string representation of this object.
    */
   public String toString()
@@ -566,20 +546,9 @@
     return getClass().getName() + "[hgap=" + hgap + ",vgap=" + vgap + "]";
   }
 
-  /**
-   * This is a convenience method to set the bounds on a component.
-   * If the indicated component is null, nothing is done.
-   */
-  private void setBounds(Component comp, int x, int y, int w, int h)
-  {
-    if (comp == null)
-      return;
-    comp.setBounds(x, y, w, h);
-  }
-
   private Dimension calcCompSize(Component comp, int what)
   {
-    if (comp == null || !comp.isVisible())
+    if (comp == null || ! comp.isVisible())
       return new Dimension(0, 0);
     if (what == MIN)
       return comp.getMinimumSize();

Reply via email to