for (int i = 0; i < rowCount; i++) {
TablePane.Row row = rows.get(i);
for (int j = 0, n = row.getLength(); j < n && j < columnCount; j++) {
Component component = row.get(j);
if (component != null
&& component.isVisible()) {
int rowSpan = TablePane.getRowSpan(component);
if (rowSpan > 1) {
// We might need to adjust row heights to accomodate
// this spanning cell. First, we find out if any of the
// spanned cells are default height and how much space
// we've allocated thus far for those cells
boolean adjustCells = true;
int spannedDefaultHeightCellCount = 0;
int spannedHeight = 0;
for (int k = 0; k < rowSpan && i + k < rowCount; k++) {
if (rowHeights[i + k] < 0) {
adjustCells = false;
break;
}
if (defaultHeightRows[i + k]) {
spannedDefaultHeightCellCount++;
}
spannedHeight += rowHeights[i + k];
}
// If we span any relative-height rows, we assume
// that we'll achieve the desired spanning height when
// we divvy up the remaining space, so there's no need
// to make an adjustment here. This assumption is safe
// because our preferred height policy is to *either*
// divide the adjustment among the relative-height
// rows *or* among the default-height rows if we
// don't span any relative-height rows
if (adjustCells
&& spannedDefaultHeightCellCount > 0) {
int componentPreferredHeight =
component.getPreferredHeight(columnWidths[j]);
if (componentPreferredHeight > spannedHeight) {
// The component's preferred height is larger
// than the height we've allocated thus far, so
// an adjustment is necessary