void (final Container container) { validateInfos(container); // IMPORTANT!!! DO NOT INLINE!!! final LayoutState layoutState = myLayoutState; final DimensionInfo horizontalInfo = myHorizontalInfo; final DimensionInfo verticalInfo = myVerticalInfo; Insets insets = getInsets(container); int skipLayout = checkSetSizesFromParent(container, insets); final Dimension gap = getTotalGap(container, horizontalInfo, verticalInfo); final Dimension size = container.getSize(); size.width -= gap.width; size.height -= gap.height; final Dimension prefSize = preferredLayoutSize(container); prefSize.width -= gap.width; prefSize.height -= gap.height; final Dimension minSize = minimumLayoutSize(container); minSize.width -= gap.width; minSize.height -= gap.height; // Calculate rows' heights if ((skipLayout & SKIP_ROW) == 0) { final int[] heights; if (mySameSizeVertically) { heights = getSameSizes(verticalInfo, Math.max(size.height, minSize.height)); } else { if (size.height < prefSize.height) { heights = getMinSizes(verticalInfo); new_doIt(heights, 0, verticalInfo.getCellCount(), size.height, verticalInfo, true); } else { heights = getPrefSizes(verticalInfo); new_doIt(heights, 0, verticalInfo.getCellCount(), size.height, verticalInfo, false); } } // Calculate rows' bounds int y = insets.top + myMargin.top; for (int i = 0; i < heights.length; i++) { myYs[i] = y; myHeights[i] = heights[i]; y += heights[i]; if (shouldAddGapAfterCell(verticalInfo, i)) { y += verticalInfo.getGap(); } } } if ((skipLayout & SKIP_COL) == 0) { // Calculate columns' widths final int[] widths; if (mySameSizeHorizontally) { widths = getSameSizes(horizontalInfo, Math.max(size.width, minSize.width)); } else { if (size.width < prefSize.width) { widths = getMinSizes(horizontalInfo); new_doIt(widths, 0, horizontalInfo.getCellCount(), size.width, horizontalInfo, true); } else { widths = getPrefSizes(horizontalInfo); new_doIt(widths, 0, horizontalInfo.getCellCount(), size.width, horizontalInfo, false); } } // Calculate columns' bounds int x = insets.left + myMargin.left; for (int i = 0; i < widths.length; i++) { myXs[i] = x; myWidths[i] = widths[i]; x += widths[i]; if (shouldAddGapAfterCell(horizontalInfo, i)) { x += horizontalInfo.getGap(); } } } // Set bounds of components for (int i = 0; i < layoutState.getComponentCount(); i++) { final GridConstraints c = layoutState.getConstraints(i); final Component component = layoutState.getComponent(i); final int column = horizontalInfo.getCell(i); final int colSpan = horizontalInfo.getSpan(i); final int row = verticalInfo.getCell(i); final int rowSpan = verticalInfo.getSpan(i); final int cellWidth = myXs[column + colSpan - 1] + myWidths[column + colSpan - 1] - myXs[column]; final int cellHeight = myYs[row + rowSpan - 1] + myHeights[row + rowSpan - 1] - myYs[row]; final Dimension componentSize = new Dimension(cellWidth, cellHeight); if ((c.getFill() & GridConstraints.FILL_HORIZONTAL) == 0) { componentSize.width = Math.min(componentSize.width, horizontalInfo.getPreferredWidth(i)); } if ((c.getFill() & GridConstraints.FILL_VERTICAL) == 0) { componentSize.height = Math.min(componentSize.height, verticalInfo.getPreferredWidth(i)); } Util.adjustSize(component, c, componentSize); int dx = 0; int dy = 0; if ((c.getAnchor() & GridConstraints.ANCHOR_EAST) != 0) { dx = cellWidth - componentSize.width; } else if ((c.getAnchor() & GridConstraints.ANCHOR_WEST) == 0) { dx = (cellWidth - componentSize.width) / 2; } if ((c.getAnchor() & GridConstraints.ANCHOR_SOUTH) != 0) { dy = cellHeight - componentSize.height; } else if ((c.getAnchor() & GridConstraints.ANCHOR_NORTH) == 0) { dy = (cellHeight - componentSize.height) / 2; } int indent = Util.DEFAULT_INDENT * c.getIndent(); componentSize.width -= indent; dx += indent; component.setBounds(myXs[column] + dx, myYs[row] + dy, componentSize.width, componentSize.height); } }