Component[] components = parent.getComponents();  if (components.length == 0) return;  GridBagLayoutInfo info = getLayoutInfo (parent, PREFERREDSIZE); if (info.cols == 0 && info.rows == 0) return; layoutInfo = info;     for(int i = 0; i < components.length; i++) { Component component = components [i];   if (!component.isVisible()) continue;  GridBagConstraints constraints = lookupConstraints (component);  int cellx = sumIntArray(layoutInfo.colWidths, constraints.gridx); int celly = sumIntArray(layoutInfo.rowHeights, constraints.gridy); int cellw = sumIntArray(layoutInfo.colWidths, constraints.gridx + constraints.gridwidth) - cellx; int cellh = sumIntArray(layoutInfo.rowHeights, constraints.gridy + constraints.gridheight) - celly;  Insets insets = constraints.insets; if (insets != null) { cellx += insets.left; celly += insets.top; cellw -= insets.left + insets.right; cellh -= insets.top + insets.bottom; }  Dimension dim = component.preferredSize();     dim.width += constraints.ipadx; dim.height += constraints.ipady;  switch(constraints.fill) { case GridBagConstraints.HORIZONTAL: dim.width = cellw; break; case GridBagConstraints.VERTICAL: dim.height = cellh; break; case GridBagConstraints.BOTH: dim.width = cellw; dim.height = cellh; break; }  int x; int y;  switch(constraints.anchor) { case GridBagConstraints.NORTH: x = cellx + (cellw - dim.width) / 2; y = celly; break; case GridBagConstraints.SOUTH: x = cellx + (cellw - dim.width) / 2; y = celly + cellh - dim.height; break; case GridBagConstraints.WEST: x = cellx; y = celly + (cellh - dim.height) / 2; break; case GridBagConstraints.EAST: x = cellx + cellw - dim.width; y = celly + (cellh - dim.height) / 2; break; case GridBagConstraints.NORTHEAST: x = cellx + cellw - dim.width; y = celly; break; case GridBagConstraints.NORTHWEST: x = cellx; y = celly; break; case GridBagConstraints.SOUTHEAST: x = cellx + cellw - dim.width; y = celly + cellh - dim.height; break; case GridBagConstraints.SOUTHWEST: x = cellx; y = celly + cellh - dim.height; break; default: x = cellx + (cellw - dim.width) / 2; y = celly + (cellh - dim.height) / 2; break; }  component.setBounds(layoutInfo.pos_x + x, layoutInfo.pos_y + y, dim.width, dim.height); }
ArrangeGrid (parent);
    protected void arrangeGrid (Container parent)    {	Component[] components = parent.getComponents();	if (components.length == 0)	    return;	GridBagLayoutInfo info = getLayoutInfo (parent, PREFERREDSIZE);	if (info.cols == 0 && info.rows == 0)	    return;	layoutInfo = info;	// DEBUG	//dumpLayoutInfo (layoutInfo);    	for(int i = 0; i < components.length; i++)	{	    Component component = components [i];			    // If component is not visible we dont have to care about it.	    if (!component.isVisible())		continue;			    GridBagConstraints constraints = lookupConstraints (component);	    int cellx = sumIntArray(layoutInfo.colWidths, constraints.gridx);	    int celly = sumIntArray(layoutInfo.rowHeights, constraints.gridy);	    int cellw = sumIntArray(layoutInfo.colWidths,		constraints.gridx + constraints.gridwidth) - cellx;	    int cellh = sumIntArray(layoutInfo.rowHeights,		constraints.gridy + constraints.gridheight) - celly;	    Insets insets = constraints.insets;	    if (insets != null)	    {		cellx += insets.left;		celly += insets.top;		cellw -= insets.left + insets.right;		cellh -= insets.top + insets.bottom;	    }	    Dimension dim = component.preferredSize();	    // Note: Documentation says that padding is added on both sides, but	    // visual inspection shows that the Sun implementation only adds it	    // once, so we do the same.	    dim.width += constraints.ipadx;	    dim.height += constraints.ipady;	    switch(constraints.fill)	    {		case GridBagConstraints.HORIZONTAL:		    dim.width = cellw;		    break;		case GridBagConstraints.VERTICAL:		    dim.height = cellh;		    break;		case GridBagConstraints.BOTH:		    dim.width = cellw;		    dim.height = cellh;		    break;	    }	    int x;	    int y;	    switch(constraints.anchor)	    {		case GridBagConstraints.NORTH:		    x = cellx + (cellw - dim.width) / 2;		    y = celly;		    break;		case GridBagConstraints.SOUTH:		    x = cellx + (cellw - dim.width) / 2;		    y = celly + cellh - dim.height;		    break;		case GridBagConstraints.WEST:		    x = cellx;		    y = celly + (cellh - dim.height) / 2;		    break;		case GridBagConstraints.EAST:		    x = cellx + cellw - dim.width;		    y = celly + (cellh - dim.height) / 2;		    break;		case GridBagConstraints.NORTHEAST:		    x = cellx + cellw - dim.width;		    y = celly;		    break;		case GridBagConstraints.NORTHWEST:		    x = cellx;		    y = celly;		    break;		case GridBagConstraints.SOUTHEAST:		    x = cellx + cellw - dim.width;		    y = celly + cellh - dim.height;		    break;		case GridBagConstraints.SOUTHWEST:		    x = cellx;		    y = celly + cellh - dim.height;		    break;		default:		    x = cellx + (cellw - dim.width) / 2;		    y = celly + (cellh - dim.height) / 2;		    break;	    }	    component.setBounds(layoutInfo.pos_x + x, layoutInfo.pos_y + y, dim.width, dim.height);	}    	// DEBUG	//dumpLayoutInfo (layoutInfo);    }