Hello!

>From JDK-1.2.1 documentation about java.awt.GridBagConstraints :

int ipadx                                                                   
   This field specifies the internal padding of the component,        
   how much space to add to the minimum width of the component.                 

java.awt.GridBagLayout used to interpret ipadx and ipady as values added
to the insets, so increasing ipadx increases the size around the
component, not the component itself.

I've attached a patch fixing this broken behaviour and a test program.

The test program still shows some difference between JDK and Kaffe,
supposedly due to strange (or broken) implementation of preferredSize()
in java.awt.Frame

Pavel Roskin
import java.awt.*;
import java.util.*;
import java.applet.Applet;

public class GridBagEx1 extends Applet {

        public void init() {
                GridBagLayout gridbag = new GridBagLayout();
                GridBagConstraints c = new GridBagConstraints();

                setLayout(gridbag);

                c.ipadx = 150;
                Button button = new Button("Hello");
                gridbag.setConstraints(button, c);
                add(button);

                setSize(400, 300);
        }

        public static void main(String args[]) {
                Frame f = new Frame("GridBag Layout Example");
                GridBagEx1 ex1 = new GridBagEx1();

                ex1.init();

                f.add("Center", ex1);
                f.pack();
                f.setSize(f.getPreferredSize());
                f.show();
        }
}
Index: libraries/javalib/java/awt/GridBagLayout.java
===================================================================
RCS file: /home/cvspublic/kaffe/libraries/javalib/java/awt/GridBagLayout.java,v
retrieving revision 1.9
diff -u -r1.9 GridBagLayout.java
--- GridBagLayout.java  1999/06/13 22:29:27     1.9
+++ GridBagLayout.java  1999/06/17 23:35:50
@@ -214,8 +214,8 @@
                        y = cc.gridy;
                }
 
-               int cw = cd.width + cc.insets.left + cc.insets.right + 2 * cc.ipadx;
-               int ch = cd.height + cc.insets.top + cc.insets.bottom + 2 * cc.ipady;
+               int cw = cd.width + cc.insets.left + cc.insets.right + cc.ipadx;
+               int ch = cd.height + cc.insets.top + cc.insets.bottom + cc.ipady;
                
                int gw = cc.gridwidth;
                int gh = cc.gridheight;
@@ -430,20 +430,20 @@
                Dimension cd = c.getPreferredSize();
                int cx = x + offset.x;
                int cy = y + offset.y;
-               int cw = cd.width;
-               int ch = cd.height;
+               int cw = cd.width + cc.ipadx;
+               int ch = cd.height + cc.ipady;
 
                switch ( cc.fill ) {
                case cc.BOTH:
-                       cx += in.left + cc.ipadx;
-                       cy += in.top + cc.ipady;
-                       cw = dx - (in.left + in.right + 2 * cc.ipadx);
-                       ch = dy - (in.top + in.bottom + 2 * cc.ipady);
+                       cx += in.left;
+                       cy += in.top;
+                       cw = dx - (in.left + in.right);
+                       ch = dy - (in.top + in.bottom);
                        break;
 
                case cc.HORIZONTAL:
-                       cx += in.left + cc.ipadx;
-                       cw = dx - (in.left + in.right + 2 * cc.ipadx);
+                       cx += in.left;
+                       cw = dx - (in.left + in.right);
                        switch ( cc.anchor ) {
                        case cc.WEST:
                        case cc.CENTER:
@@ -455,20 +455,20 @@
                        case cc.NORTH:
                        case cc.NORTHEAST:
                        case cc.NORTHWEST:
-                               cy += in.top + cc.ipady;
+                               cy += in.top;
                                break;
 
                        case cc.SOUTHEAST:
                        case cc.SOUTH:
                        case cc.SOUTHWEST:
-                               cy += dy - (cd.height + in.bottom + cc.ipady);
+                               cy += dy - (cd.height + in.bottom);
                                break;
                        }
                        break;
 
                case cc.VERTICAL:
-                       cy += in.top + cc.ipady;
-                       ch = dy - (in.top + in.bottom + 2 * cc.ipady);
+                       cy += in.top;
+                       ch = dy - (in.top + in.bottom);
                        switch ( cc.anchor ) {
                        case cc.NORTH:
                        case cc.CENTER:
@@ -480,13 +480,13 @@
                        case cc.NORTHWEST:
                        case cc.WEST:
                        case cc.SOUTHWEST:
-                               cx += in.left + cc.ipadx;
+                               cx += in.left;
                                break;
 
                        case cc.NORTHEAST:
                        case cc.SOUTHEAST:
                        case cc.EAST:
-                               cx += dx - (cw + in.right + cc.ipadx);
+                               cx += dx - (cw + in.right);
                                break;
                        }
                        break;
@@ -495,43 +495,43 @@
                default:
                        switch ( cc.anchor ) {
                        case cc.NORTH:
-                               cy += in.top + cc.ipady;
+                               cy += in.top;
                                cx += (dx - cw) / 2;
                                break;
 
                        case cc.NORTHEAST:
-                               cy += in.top + cc.ipady;
-                               cx += dx - (cw + in.right + cc.ipadx);
+                               cy += in.top;
+                               cx += dx - (cw + in.right);
                                break;
 
                        case cc.EAST:
                                cy += (dy - ch) / 2;
-                               cx += dx - (cw + in.right + cc.ipadx);
+                               cx += dx - (cw + in.right);
                                break;
 
                        case cc.SOUTHEAST:
-                               cy += dy - (ch + in.bottom + cc.ipady);
-                               cx += dx - (cw + in.right + cc.ipadx);
+                               cy += dy - (ch + in.bottom);
+                               cx += dx - (cw + in.right);
                                break;
 
                        case cc.SOUTH:
-                               cy += dy - (ch + in.bottom + cc.ipady);
+                               cy += dy - (ch + in.bottom);
                                cx += (dx - cw) / 2;
                                break;
 
                        case cc.SOUTHWEST:
-                               cy += dy - (ch + in.bottom + cc.ipady);
-                               cx += in.left + cc.ipadx;
+                               cy += dy - (ch + in.bottom);
+                               cx += in.left;
                                break;
 
                        case cc.WEST:
                                cy += (dy - ch) / 2;
-                               cx += in.left + cc.ipadx;
+                               cx += in.left;
                                break;
 
                        case cc.NORTHWEST:
-                               cy += in.top + cc.ipady;
-                               cx += in.left + cc.ipadx;
+                               cy += in.top;
+                               cx += in.left;
                                break;
 
                        case cc.CENTER:

Reply via email to