void updateGrid(){
  if (!gridValid) {
    rows.removeAllElements();
    int n=getViewCount();
    for (int i=0; i < n; i++) {
      View v=getView(i);
      if (v instanceof TableRow) {
        rows.addElement((TableRow)v);
        TableRow rv=(TableRow)v;
        rv.clearFilledColumns();
        rv.setRow(i);
      }
    }
    int maxColumns=0;
    int nrows=rows.size();
    for (int row=0; row < nrows; row++) {
      TableRow rv=getRow(row);
      int col=0;
      for (int cell=0; cell < rv.getViewCount(); cell++, col++) {
        View cv=rv.getView(cell);
        for (; rv.isFilled(col); col++)         ;
        int rowSpan=getRowsOccupied(cv);
        int colSpan=getColumnsOccupied(cv);
        if ((colSpan > 1) || (rowSpan > 1)) {
          int rowLimit=row + rowSpan;
          int colLimit=col + colSpan;
          for (int i=row; i < rowLimit; i++) {
            for (int j=col; j < colLimit; j++) {
              if (i != row || j != col) {
                addFill(i,j);
              }
            }
          }
          if (colSpan > 1) {
            col+=colSpan - 1;
          }
        }
      }
      maxColumns=Math.max(maxColumns,col);
    }
    columnSpans=new int[maxColumns];
    columnOffsets=new int[maxColumns];
    columnRequirements=new SizeRequirements[maxColumns];
    for (int i=0; i < maxColumns; i++) {
      columnRequirements[i]=new SizeRequirements();
    }
    gridValid=true;
  }
}

void updateGrid ( ) { if ( ! gridValid ) { rows . removeAllElements ( ) ; int n = getViewCount ( ) ; for ( int i = 0 ; i < n ; i ++ ) { View v = getView ( i ) ; if ( v instanceof TableRow ) { rows . addElement ( ( TableRow ) v ) ; TableRow rv = ( TableRow ) v ; rv . clearFilledColumns ( ) ; rv . setRow ( i ) ; } } int maxColumns = 0 ; int nrows = rows . size ( ) ; for ( int row = 0 ; row < nrows ; row ++ ) { TableRow rv = getRow ( row ) ; int col = 0 ; for ( int cell = 0 ; cell < rv . getViewCount ( ) ; cell ++ , col ++ ) { View cv = rv . getView ( cell ) ; for ( ; rv . isFilled ( col ) ; col ++ ) ; int rowSpan = getRowsOccupied ( cv ) ; int colSpan = getColumnsOccupied ( cv ) ; if ( ( colSpan > 1 ) || ( rowSpan > 1 ) ) { int rowLimit = row + rowSpan ; int colLimit = col + colSpan ; for ( int i = row ; i < rowLimit ; i ++ ) { for ( int j = col ; j < colLimit ; j ++ ) { if ( i != row || j != col ) { addFill ( i , j ) ; } } } if ( colSpan > 1 ) { col += colSpan - 1 ; } } } maxColumns = Math . max ( maxColumns , col ) ; } columnSpans = new int [ maxColumns ] ; columnOffsets = new int [ maxColumns ] ; columnRequirements = new SizeRequirements [ maxColumns ] ; for ( int i = 0 ; i < maxColumns ; i ++ ) { columnRequirements [ i ] = new SizeRequirements ( ) ; } gridValid = true ; } }
fill in the grid locations that are placeholders for multi - column , multi - row , and missing grid locations .
