Home » iText-2.1.7 » com.lowagie » text » [javadoc | source]
com.lowagie.text
public class: Table [javadoc | source]
java.lang.Object
   com.lowagie.text.Rectangle
      com.lowagie.text.Table

All Implemented Interfaces:
    LargeElement, Element

A Table is a Rectangle that contains Cells, ordered in some kind of matrix.

Tables that span multiple pages are cut into different parts automatically. If you want a table header to be repeated on every page, you may not forget to mark the end of the header section by using the method endHeaders().

The matrix of a table is not necessarily an m x n-matrix. It can contain holes or cells that are bigger than the unit. Believe me or not, but it took some serious thinking to make this as user friendly as possible. I hope you will find the result quite simple (I love simple solutions, especially for complex problems). I didn't want it to be something as complex as the Java GridBagLayout.

Example:

// Remark: You MUST know the number of columns when constructing a Table.
//         The number of rows is not important.
Table table = new Table(3);
table.setBorderWidth(1);
table.setBorderColor(new Color(0, 0, 255));
table.setPadding(5);
table.setSpacing(5);
Cell cell = new Cell("header");
cell.setHeader(true);
cell.setColspan(3);
table.addCell(cell);
table.endHeaders();
cell = new Cell("example cell with colspan 1 and rowspan 2");
cell.setRowspan(2);
cell.setBorderColor(new Color(255, 0, 0));
table.addCell(cell);
table.addCell("1.1");
table.addCell("2.1");
table.addCell("1.2");
table.addCell("2.2");
table.addCell("cell test1");
cell = new Cell("big cell");
cell.setRowspan(2);
cell.setColspan(2);
table.addCell(cell);
table.addCell("cell test2");
The result of this code is a table:
header
example cell with colspan 1 and rowspan 2 1.1 2.1
1.2 2.2
cell test1 big cell
cell test2
Field Summary
protected  boolean autoFillEmptyCells    Boolean to automatically fill empty cells before a table is rendered (takes CPU so may be set to false in case of certainty) 
 boolean tableFitsPage    If true this table may not be split over two pages. 
 boolean cellsFitPage    If true cells may not be split over two pages. 
 float offset    This is the offset of the table. 
protected  boolean convert2pdfptable    if you want to generate tables the old way, set this value to false. 
protected  boolean notAddedYet    Indicates if this is the first time the section was added.
    since: iText - 2.0.8
 
protected  boolean complete    Indicates if the PdfPTable is complete once added to the document.
    since: iText - 2.0.8
 
Fields inherited from com.lowagie.text.Rectangle:
UNDEFINED,  TOP,  BOTTOM,  LEFT,  RIGHT,  NO_BORDER,  BOX,  llx,  lly,  urx,  ury,  rotation,  backgroundColor,  border,  useVariableBorders,  borderWidth,  borderWidthLeft,  borderWidthRight,  borderWidthTop,  borderWidthBottom,  borderColor,  borderColorLeft,  borderColorRight,  borderColorTop,  borderColorBottom
Constructor:
 public Table(int columns) throws BadElementException 
    Constructs a Table with a certain number of columns.
    Parameters:
    columns - The number of columns in the table
    Throws:
    BadElementException - if the creator was called with less than 1 column
 public Table(Table t) 
    Copy constructor (shallow copy).
 public Table(int columns,
    int rows) throws BadElementException 
    Constructs a Table with a certain number of columns and a certain number of Rows.
    Parameters:
    columns - The number of columns in the table
    rows - The number of rows
    Throws:
    BadElementException - if the creator was called with less than 1 column
Method from com.lowagie.text.Table Summary:
addCell,   addCell,   addCell,   addCell,   addCell,   addCell,   addCell,   addColumns,   complete,   createPdfPTable,   deleteAllRows,   deleteColumn,   deleteLastRow,   deleteRow,   endHeaders,   flushContent,   getAlignment,   getChunks,   getColumns,   getDefaultCell,   getDefaultLayout,   getDimension,   getElement,   getLastHeaderRow,   getOffset,   getPadding,   getProportionalWidths,   getSpacing,   getWidth,   getWidths,   insertTable,   insertTable,   insertTable,   isCellsFitPage,   isComplete,   isConvert2pdfptable,   isLocked,   isNestable,   isNotAddedYet,   isTableFitsPage,   iterator,   process,   setAlignment,   setAlignment,   setAutoFillEmptyCells,   setCellsFitPage,   setComplete,   setConvert2pdfptable,   setDefaultCell,   setDefaultLayout,   setLastHeaderRow,   setLocked,   setNotAddedYet,   setOffset,   setPadding,   setSpacing,   setTableFitsPage,   setWidth,   setWidths,   setWidths,   size,   type
Methods from com.lowagie.text.Rectangle:
cloneNonPositionParameters,   disableBorderSide,   enableBorderSide,   getBackgroundColor,   getBorder,   getBorderColor,   getBorderColorBottom,   getBorderColorLeft,   getBorderColorRight,   getBorderColorTop,   getBorderWidth,   getBorderWidthBottom,   getBorderWidthLeft,   getBorderWidthRight,   getBorderWidthTop,   getBottom,   getBottom,   getChunks,   getGrayFill,   getHeight,   getLeft,   getLeft,   getRight,   getRight,   getRotation,   getTop,   getTop,   getWidth,   hasBorder,   hasBorders,   isContent,   isNestable,   isUseVariableBorders,   normalize,   process,   rectangle,   rotate,   setBackgroundColor,   setBorder,   setBorderColor,   setBorderColorBottom,   setBorderColorLeft,   setBorderColorRight,   setBorderColorTop,   setBorderWidth,   setBorderWidthBottom,   setBorderWidthLeft,   setBorderWidthRight,   setBorderWidthTop,   setBottom,   setGrayFill,   setLeft,   setRight,   setTop,   setUseVariableBorders,   softCloneNonPositionParameters,   toString,   type
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from com.lowagie.text.Table Detail:
 public  void addCell(Cell cell) 
    Adds a Cell to the Table.
 public  void addCell(Phrase content) throws BadElementException 
    Adds a Cell to the Table.

    This is a shortcut for addCell(Cell cell). The Phrase will be converted to a Cell.

 public  void addCell(String content) throws BadElementException 
    Adds a Cell to the Table.

    This is a shortcut for addCell(Cell cell). The String will be converted to a Cell.

 public  void addCell(Cell aCell,
    Point aLocation) throws BadElementException 
    Adds a Cell to the Table at a certain location.
 public  void addCell(Phrase content,
    Point location) throws BadElementException 
    Adds a Cell to the Table.

    This is a shortcut for addCell(Cell cell, Point location). The Phrase will be converted to a Cell.

 public  void addCell(String content,
    Point location) throws BadElementException 
    Adds a Cell to the Table.

    This is a shortcut for addCell(Cell cell, Point location). The String will be converted to a Cell.

 public  void addCell(Cell aCell,
    int row,
    int column) throws BadElementException 
    Adds a Cell to the Table at a certain row and column.
 public  void addColumns(int aColumns) 
    Gives you the possibility to add columns.
 public  void complete() 
    Will fill empty cells with valid blank Cells
 public PdfPTable createPdfPTable() throws BadElementException 
    Create a PdfPTable based on this Table object.
 public  void deleteAllRows() 
    Deletes all rows in this table. (contributed by dperezcar@fcc.es)
 public  void deleteColumn(int column) throws BadElementException 
    Deletes a column in this table.
 public boolean deleteLastRow() 
    Deletes the last row in this table.
 public boolean deleteRow(int row) 
    Deletes a row.
 public int endHeaders() 
    Marks the last row of the table headers.
 public  void flushContent() 
 public int getAlignment() 
    Gets the horizontal alignment.
 public ArrayList getChunks() 
    Gets all the chunks in this element.
 public int getColumns() 
    Gets the number of columns.
 public Cell getDefaultCell() 
    Gets the default layout of the Table.
 public Cell getDefaultLayout() 
Deprecated! As - of iText 2.0.7, replaced by #getDefaultCell() , scheduled for removal at 2.2.0

    Gets the default layout of the Table.
 public Dimension getDimension() 
    Gets the dimension of this table
 public Object getElement(int row,
    int column) 
    returns the element at the position row, column (Cast to Cell or Table)
 public int getLastHeaderRow() 
    Gets the last number of the rows that contain headers.
 public float getOffset() 
    Gets the offset of this table.
 public float getPadding() 
    Gets the cellpadding.
 public float[] getProportionalWidths() 
    Gets the proportional widths of the columns in this Table.
 public float getSpacing() 
    Gets the cellspacing.
 public float getWidth() 
    Gets the table width (a percentage).
 public float[] getWidths(float left,
    float totalWidth) 
    Gets an array with the positions of the borders between every column.

    This method translates the widths expressed in percentages into the x-coordinate of the borders of the columns on a real document.

 public  void insertTable(Table aTable) 
    To put a table within the existing table at the current position generateTable will of course re-arrange the widths of the columns.
 public  void insertTable(Table aTable,
    Point aLocation) 
    To put a table within the existing table at the given position generateTable will of course re-arrange the widths of the columns.
 public  void insertTable(Table aTable,
    int row,
    int column) 
    To put a table within the existing table at the given position generateTable will of course re-arrange the widths of the columns.
 public boolean isCellsFitPage() 
    Checks if the cells of this Table have to fit a page.
 public boolean isComplete() 
 public boolean isConvert2pdfptable() 
    Method to check if the Table should be converted to a PdfPTable or not.
 public boolean isLocked() 
 public boolean isNestable() 
 public boolean isNotAddedYet() 
    Indicates if this is the first time the section is added.
 public boolean isTableFitsPage() 
    Checks if this Table has to fit a page.
 public Iterator iterator() 
    Gets an Iterator of all the Rows.
 public boolean process(ElementListener listener) 
    Processes the element by adding it (or the different parts) to an ElementListener.
 public  void setAlignment(int value) 
    Sets the horizontal alignment.
 public  void setAlignment(String alignment) 
    Sets the alignment of this paragraph.
 public  void setAutoFillEmptyCells(boolean aDoAutoFill) 
    Enables/disables automatic insertion of empty cells before table is rendered. (default = false) As some people may want to create a table, fill only a couple of the cells and don't bother with investigating which empty ones need to be added, this default behavior may be very welcome. Disabling is recommended to increase speed. (empty cells should be added through extra code then)
 public  void setCellsFitPage(boolean fitPage) 
    Allows you to control when a page break occurs.

    When a cell doesn't fit a page, it is split in two parts. If you want to avoid this, you should set the cellsFitPage value to true.

 public  void setComplete(boolean complete) 
 public  void setConvert2pdfptable(boolean convert2pdfptable) 
    If set to true, iText will try to convert the Table to a PdfPTable.
 public  void setDefaultCell(Cell value) 
    Sets the default layout of the Table to the provided Cell
 public  void setDefaultLayout(Cell value) 
Deprecated! As - of iText 2.0.7, replaced by #setDefaultCell(Cell) , scheduled for removal at 2.2.0

    Sets the default layout of the Table to the provided Cell
 public  void setLastHeaderRow(int value) 
    Sets the horizontal alignment.
 public  void setLocked(boolean locked) 
 public  void setNotAddedYet(boolean notAddedYet) 
    Sets the indication if the section was already added to the document.
 public  void setOffset(float offset) 
    Sets the offset of this table. Normally a newline is added before you add a Table object. This newline uses the current leading. If you want to control the space between the table and the previous element yourself, you have to set the offset of this table.
 public  void setPadding(float value) 
    Sets the cellpadding.
 public  void setSpacing(float value) 
    Sets the cellspacing.
 public  void setTableFitsPage(boolean fitPage) 
    Allows you to control when a page break occurs.

    When a table doesn't fit a page, it is split in two parts. If you want to avoid this, you should set the tableFitsPage value to true.

 public  void setWidth(float width) 
    Sets the width of this table (in percentage of the available space).
 public  void setWidths(float[] widths) throws BadElementException 
    Sets the widths of the different columns (percentages).

    You can give up relative values of borderwidths. The sum of these values will be considered 100%. The values will be recalculated as percentages of this sum.

    example:

    float[] widths = {2, 1, 1};
    table.setWidths(widths)
    
    The widths will be: a width of 50% for the first column, 25% for the second and third column.
 public  void setWidths(int[] widths) throws DocumentException 
    Sets the widths of the different columns (percentages).

    You can give up relative values of borderwidths. The sum of these values will be considered 100%. The values will be recalculated as percentages of this sum.

 public int size() 
    Gets the number of rows in this Table.
 public int type() 
    Gets the type of the text element.