Setting a Cell's Width and Height

Setting the width or height of a cell uses the same paradigm as dragging the borders of cells in PowerPoint. In the library, if you set the width of one cell this will set the width of all cells in that column. Likewise if you set a row's height, this will set the height of all cells in the row (and change the height of the overall table).

To obtain a cell's width use:

int getCellWidth(int row, int column)

To set a cell's width use:

void setCellWidth(int row, int column, int width)

To obtain a row's height use:

int getRowHeight(int row)

To set a row's height use:

void setRowHeight(int row, int height)

For example, once a table has been created, content added and formatted, a common desire is to resize the table to fit its contents. The following method dies this by setting the height of each row to fit the largest cell in the row.

public static void resizeTable(Table table)
{
    for (int row = 0; row < table.getRowCount(); row++) {
        int height = 0;
        for (int column = 0; column < table.getColumnCount(); column++) {
            TextShape cell = table.getCell(row, column);
            if (cell != null)
                height = Math.max(height, cell.getBoundsToFitText().height);
        }
        table.setRowHeight(row, height);
    }
}

Page generated: 2008-01-18 02:53:28 GMT TonicPoint Builder Developer's Guide -- Version 2.3