if (sizeflag != MINSIZE && sizeflag != PREFERREDSIZE) throw new IllegalArgumentException();  Dimension parentDim = parent.size(); Insets parentInsets = parent.insets(); parentDim.width -= parentInsets.left + parentInsets.right; parentDim.height -= parentInsets.top + parentInsets.bottom;  int x = 0; int y = 0; int max_x = 0; int max_y = 0;   Component[] components = parent.getComponents(); for (int i = 0; i < components.length; i++) { Component component = components [i];   if (!component.isVisible()) continue;  GridBagConstraints constraints = lookupConstraints (component);  if(constraints.gridx == GridBagConstraints.RELATIVE) constraints.gridx = x;  if(constraints.gridy == GridBagConstraints.RELATIVE) constraints.gridy = y;  max_x = Math.max(max_x, constraints.gridx + Math.max(1, constraints.gridwidth)); max_y = Math.max(max_y, constraints.gridy + Math.max(1, constraints.gridheight));  if(constraints.gridwidth == GridBagConstraints.REMAINDER) { x = 0; y++; } else { x = constraints.gridx + Math.max(1, constraints.gridwidth); y = constraints.gridy; } }  GridBagLayoutInfo info = new GridBagLayoutInfo(max_x, max_y);  for (x = 0; x <= max_x; x++) { if(columnWidths != null && columnWidths.length > x) { info.colWidths[x] = columnWidths[x]; } if(columnWeights != null && columnWeights.length > x) { info.colWeights[x] = columnWeights[x]; } for (int i = 0; i < components.length; i++) { Component component = components [i];   if (!component.isVisible()) continue;  GridBagConstraints constraints = lookupConstraints (component);   if(constraints.gridwidth == GridBagConstraints.REMAINDER) { constraints.gridwidth = max_x - constraints.gridx; } if(constraints.gridheight == GridBagConstraints.REMAINDER) { constraints.gridheight = max_y - constraints.gridy; }  if(constraints.gridx + constraints.gridwidth - 1 == x) { int width = (sizeflag == PREFERREDSIZE) ? component.preferredSize().width : component.minimumSize().width; if(constraints.insets != null) { width += constraints.insets.left + constraints.insets.right; } width += constraints.ipadx; for(int w = 1; w < constraints.gridwidth; w++) { width -= info.colWidths[x - w]; } info.colWidths[x] = Math.max(info.colWidths[x], width); info.colWeights[x] = Math.max(info.colWeights[x], constraints.weightx); } } }  for (y = 0; y <= max_y; y++) { if(rowHeights != null && rowHeights.length > y) { info.rowHeights[y] = rowHeights[y]; } if(rowWeights != null && rowWeights.length > y) { info.rowWeights[y] = rowWeights[y]; } for (int i = 0; i < components.length; i++) { Component component = components [i];   if (!component.isVisible()) continue;  GridBagConstraints constraints = lookupConstraints (component);  if(constraints.gridy + constraints.gridheight - 1 == y) { int height = (sizeflag == PREFERREDSIZE) ? component.preferredSize().height : component.minimumSize().height; if(constraints.insets != null) { height += constraints.insets.top + constraints.insets.bottom; } height += constraints.ipady; for(int h = 1; h < constraints.gridheight; h++) { height -= info.rowHeights[y - h]; } info.rowHeights[y] = Math.max(info.rowHeights[y], height); info.rowWeights[y] = Math.max(info.rowWeights[y], constraints.weighty); } } }  calcCellSizes (info.colWidths, info.colWeights, parentDim.width); calcCellSizes (info.rowHeights, info.rowWeights, parentDim.height);  int totalWidth = sumIntArray(info.colWidths); int totalHeight = sumIntArray(info.rowHeights); info.pos_x = parentInsets.left + (parentDim.width - totalWidth) / 2; info.pos_y = parentInsets.top + (parentDim.height - totalHeight) / 2;     return info;
return GetLayoutInfo (parent, sizeflag);
    protected GridBagLayoutInfo getLayoutInfo (Container parent, int sizeflag)    {	if (sizeflag != MINSIZE && sizeflag != PREFERREDSIZE)	    throw new IllegalArgumentException();	Dimension parentDim = parent.size();	Insets parentInsets = parent.insets();	parentDim.width -= parentInsets.left + parentInsets.right;	parentDim.height -= parentInsets.top + parentInsets.bottom;   	int x = 0;	int y = 0;	int max_x = 0;	int max_y = 0;	// first we figure out how many rows/columns	Component[] components = parent.getComponents();	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);			    if(constraints.gridx == GridBagConstraints.RELATIVE)		constraints.gridx = x;	    if(constraints.gridy == GridBagConstraints.RELATIVE)		constraints.gridy = y;			    max_x = Math.max(max_x, 		constraints.gridx + Math.max(1, constraints.gridwidth));	    max_y = Math.max(max_y,		constraints.gridy + Math.max(1, constraints.gridheight));	    if(constraints.gridwidth == GridBagConstraints.REMAINDER)	    {		x = 0;		y++;	    }	    else	    {		x = constraints.gridx + Math.max(1, constraints.gridwidth);		y = constraints.gridy;	    }	}		GridBagLayoutInfo info = new GridBagLayoutInfo(max_x, max_y);	for (x = 0; x <= max_x; x++)	{	    if(columnWidths != null && columnWidths.length > x)	    {		info.colWidths[x] = columnWidths[x];	    }	    if(columnWeights != null && columnWeights.length > x)	    {		info.colWeights[x] = columnWeights[x];	    }	    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);		// first we fix up any REMAINDER cells		if(constraints.gridwidth == GridBagConstraints.REMAINDER)		{		    constraints.gridwidth = max_x - constraints.gridx;		}		if(constraints.gridheight == GridBagConstraints.REMAINDER)		{		    constraints.gridheight = max_y - constraints.gridy;		}		if(constraints.gridx + constraints.gridwidth - 1 == x)		{		    int width = (sizeflag == PREFERREDSIZE) ?			component.preferredSize().width :			component.minimumSize().width;		    if(constraints.insets != null)		    {			width += constraints.insets.left + constraints.insets.right;		    }		    width += constraints.ipadx;		    for(int w = 1; w < constraints.gridwidth; w++)		    {			width -= info.colWidths[x - w];		    }		    info.colWidths[x] = Math.max(info.colWidths[x], width);		    info.colWeights[x] =			Math.max(info.colWeights[x], constraints.weightx);		}	    }	}	for (y = 0; y <= max_y; y++)	{	    if(rowHeights != null && rowHeights.length > y)	    {		info.rowHeights[y] = rowHeights[y];	    }	    if(rowWeights != null && rowWeights.length > y)	    {		info.rowWeights[y] = rowWeights[y];	    }	    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);		if(constraints.gridy + constraints.gridheight - 1 == y)		{		    int height = (sizeflag == PREFERREDSIZE) ?			component.preferredSize().height :			component.minimumSize().height;		    if(constraints.insets != null)		    {			height += constraints.insets.top + constraints.insets.bottom;		    } 		    height += constraints.ipady;		    for(int h = 1; h < constraints.gridheight; h++)		    {			height -= info.rowHeights[y - h];		    }		    info.rowHeights[y] = Math.max(info.rowHeights[y], height);		    info.rowWeights[y] =			Math.max(info.rowWeights[y], constraints.weighty);		}	    }	}	calcCellSizes (info.colWidths, info.colWeights, parentDim.width);	calcCellSizes (info.rowHeights, info.rowWeights, parentDim.height);	int totalWidth = sumIntArray(info.colWidths);	int totalHeight = sumIntArray(info.rowHeights);	info.pos_x = parentInsets.left + (parentDim.width - totalWidth) / 2;	info.pos_y = parentInsets.top + (parentDim.height - totalHeight) / 2;	// DEBUG	//dumpLayoutInfo (info);	return info;    }