com.lowagie.text

## Class Cell

- java.lang.Object
- - com.lowagie.text.Rectangle
  - - com.lowagie.text.Cell

All Implemented Interfaces:
  Element, TextElementArray

Direct Known Subclasses:
  RtfCell

    public class Cell
    extends Rectangle
    implements TextElementArray

A `Cell` is a `Rectangle` containing other `Element`s.

A `Cell` must be added to a `Table`. The `Table` will place the `Cell` in a `Row`.

Example:

>      Table table = new Table(3);
>      table.setBorderWidth(1);
>      table.setBorderColor(new Color(0, 0, 255));
>      table.setCellpadding(5);
>      table.setCellspacing(5);
>      Cell cell = new Cell("header");
>      cell.setHeader(true);
>      cell.setColspan(3);
>      table.addCell(cell);
>      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");

See Also:
  `Rectangle`, `Element`, `Table`, `Row`

### Field Summary

Fields
`protected java.util.ArrayList` `arrayList` The `ArrayList` of `Element`s that are part of the content of the Cell.
`protected int` `colspan` The colspan of the cell.
`protected boolean` `groupChange` Does this `Cell` force a group change?
`protected boolean` `header` Is this `Cell` a header?
`protected int` `horizontalAlignment` The horizontal alignment of the cell content.
`(package private) float` `leading` The leading of the content inside the cell.
`protected int` `maxLines` Maximum number of lines allowed in the cell.
`protected boolean` `percentage`
`protected int` `rowspan` The rowspan of the cell.
`(package private) java.lang.String` `showTruncation` If a truncation happens due to the maxLines property, then this text will be added to indicate a truncation has happened.
`protected boolean` `useAscender` Indicates that the largest ascender height should be used to determine the height of the first line.
`protected boolean` `useBorderPadding` Adjusts the cell contents to compensate for border widths.
`protected boolean` `useDescender` Indicates that the largest descender height should be added to the height of the last line (so characters like y don't dip into the border).
`protected int` `verticalAlignment` The vertical alignment of the cell content.
`protected float` `width` The width of the cell as a String.

### Fields inherited from class com.lowagie.text.Rectangle

`backgroundColor, border, borderColor, borderColorBottom, borderColorLeft, borderColorRight, borderColorTop, borderWidth, borderWidthBottom, borderWidthLeft, borderWidthRight, borderWidthTop, BOTTOM, BOX, LEFT, llx, lly, NO_BORDER, RIGHT, rotation, TOP, UNDEFINED, urx, ury, useVariableBorders`

### Fields inherited from interface com.lowagie.text.Element

`ALIGN_BASELINE, ALIGN_BOTTOM, ALIGN_CENTER, ALIGN_JUSTIFIED, ALIGN_JUSTIFIED_ALL, ALIGN_LEFT, ALIGN_MIDDLE, ALIGN_RIGHT, ALIGN_TOP, ALIGN_UNDEFINED, ANCHOR, ANNOTATION, AUTHOR, CCITT_BLACKIS1, CCITT_ENCODEDBYTEALIGN, CCITT_ENDOFBLOCK, CCITT_ENDOFLINE, CCITTG3_1D, CCITTG3_2D, CCITTG4, CELL, CHAPTER, CHUNK, CREATIONDATE, CREATOR, HEADER, IMGRAW, IMGTEMPLATE, JBIG2, JPEG, JPEG2000, KEYWORDS, LIST, LISTITEM, MARKED, MULTI_COLUMN_TEXT, PARAGRAPH, PHRASE, PRODUCER, PTABLE, RECTANGLE, ROW, SECTION, SUBJECT, TABLE, TITLE, YMARK`

### Constructor Summary

Constructors
Constructor and Description
`Cell()` Constructs an empty `Cell`.
`Cell(boolean dummy)` Constructs an empty `Cell` (for internal use only).
`Cell(Element element)` Constructs a `Cell` with a certain `Element`.
`Cell(java.lang.String content)` Constructs a `Cell` with a certain content.

### Method Summary

Methods
`boolean` `add(java.lang.Object o)` Add an `Object` to this cell.
`void` `addElement(Element element)` Adds an element to this `Cell`.
`float` `bottom(int margin)` This method throws an `UnsupportedOperationException`.
`void` `clear()` Clears all the `Element`s of this `Cell`.
`PdfPCell` `createPdfPCell()` Creates a PdfPCell based on this Cell object.
`(package private) void` `fill()` Makes sure there is at least 1 object in the Cell.
`float` `getBottom()` This method throws an `UnsupportedOperationException`.
`java.util.ArrayList` `getChunks()` Gets all the chunks in this element.
`int` `getColspan()` Gets the colspan.
`private static Cell` `getDummyCell()` Get dummy cell used when merging inner tables.
`java.util.Iterator` `getElements()` Gets an iterator of `Element`s.
`boolean` `getGroupChange()` Does this `Cell` force a group change?
`int` `getHorizontalAlignment()` Gets the horizontal alignment.
`float` `getLeading()` Gets the leading.
`float` `getLeft()` This method throws an `UnsupportedOperationException`.
`int` `getMaxLines()` Getter for maxLines
`float` `getRight()` This method throws an `UnsupportedOperationException`.
`int` `getRowspan()` Gets the rowspan.
`java.lang.String` `getShowTruncation()` Getter for showTruncation
`float` `getTop()` This method throws an `UnsupportedOperationException`.
`int` `getVerticalAlignment()` Gets the vertical alignment.
`float` `getWidth()` Gets the width.
`java.lang.String` `getWidthAsString()` Gets the width as a String.
`boolean` `isEmpty()` Checks if the `Cell` is empty.
`boolean` `isHeader()` Is this `Cell` a header?
`boolean` `isTable()` Checks if this `Cell` is a placeholder for a (nested) table.
`boolean` `isUseAscender()` Gets the value of useAscender
`boolean` `isUseBorderPadding()` Gets the value of useBorderPadding.
`boolean` `isUseDescender()` gets the value of useDescender
`float` `left(int margin)` This method throws an `UnsupportedOperationException`.
`boolean` `process(ElementListener listener)` Processes the element by adding it (or the different parts) to an `ElementListener`.
`float` `right(int margin)` This method throws an `UnsupportedOperationException`.
`void` `setBottom(int value)` This method throws an `UnsupportedOperationException`.
`void` `setColspan(int value)` Sets the colspan.
`void` `setGroupChange(boolean value)` Sets group change.
`void` `setHeader(boolean value)` Sets header.
`void` `setHorizontalAlignment(int value)` Sets the horizontal alignment.
`void` `setHorizontalAlignment(java.lang.String alignment)` Sets the alignment of this cell.
`void` `setLeading(float value)` Sets the leading.
`void` `setLeft(int value)` This method throws an `UnsupportedOperationException`.
`void` `setMaxLines(int value)` Setter for maxLines
`void` `setRight(int value)` This method throws an `UnsupportedOperationException`.
`void` `setRowspan(int value)` Sets the rowspan.
`void` `setShowTruncation(java.lang.String value)` Setter for showTruncation
`void` `setTop(int value)` This method throws an `UnsupportedOperationException`.
`void` `setUseAscender(boolean use)` Sets the value of useAscender.
`void` `setUseBorderPadding(boolean use)` Sets the value of useBorderPadding.
`void` `setUseDescender(boolean use)` Sets the value of useDescender.
`void` `setVerticalAlignment(int value)` Sets the vertical alignment.
`void` `setVerticalAlignment(java.lang.String alignment)` Sets the alignment of this paragraph.
`void` `setWidth(float value)` Sets the width.
`void` `setWidth(java.lang.String value)` Sets the width.
`int` `size()` Gets the number of `Element`s in the Cell.
`float` `top(int margin)` This method throws an `UnsupportedOperationException`.
`int` `type()` Gets the type of the text element.

### Methods inherited from class com.lowagie.text.Rectangle

`cloneNonPositionParameters, disableBorderSide, enableBorderSide, getBackgroundColor, getBorder, getBorderColor, getBorderColorBottom, getBorderColorLeft, getBorderColorRight, getBorderColorTop, getBorderWidth, getBorderWidthBottom, getBorderWidthLeft, getBorderWidthRight, getBorderWidthTop, getBottom, getGrayFill, getHeight, getLeft, getRight, getRotation, getTop, hasBorder, hasBorders, isContent, isNestable, isUseVariableBorders, normalize, rectangle, rotate, setBackgroundColor, setBorder, setBorderColor, setBorderColorBottom, setBorderColorLeft, setBorderColorRight, setBorderColorTop, setBorderWidth, setBorderWidthBottom, setBorderWidthLeft, setBorderWidthRight, setBorderWidthTop, setBottom, setGrayFill, setLeft, setRight, setTop, setUseVariableBorders, softCloneNonPositionParameters, toString`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Methods inherited from interface com.lowagie.text.Element

`isContent, isNestable, toString`

### Field Detail

#### arrayList

    protected java.util.ArrayList arrayList

The `ArrayList` of `Element`s that are part of the content of the Cell.

#### horizontalAlignment

    protected int horizontalAlignment

The horizontal alignment of the cell content.

#### verticalAlignment

    protected int verticalAlignment

The vertical alignment of the cell content.

#### width

    protected float width

The width of the cell as a String. It can be an absolute value "100" or a percentage "20%".

#### percentage

    protected boolean percentage

#### colspan

    protected int colspan

The colspan of the cell.

#### rowspan

    protected int rowspan

The rowspan of the cell.

#### leading

    float leading

The leading of the content inside the cell.

#### header

    protected boolean header

Is this `Cell` a header?

#### maxLines

    protected int maxLines

Maximum number of lines allowed in the cell. The default value of this property is not to limit the maximum number of lines (contributed by dperezcar@fcc.es)

#### showTruncation

    java.lang.String showTruncation

If a truncation happens due to the maxLines property, then this text will be added to indicate a truncation has happened. Default value is null, and means avoiding marking the truncation. A useful value of this property could be e.g. "..." (contributed by dperezcar@fcc.es)

#### useAscender

    protected boolean useAscender

Indicates that the largest ascender height should be used to determine the height of the first line. Note that this only has an effect when rendered to PDF. Setting this to true can help with vertical alignment problems.

#### useDescender

    protected boolean useDescender

Indicates that the largest descender height should be added to the height of the last line (so characters like y don't dip into the border). Note that this only has an effect when rendered to PDF.

#### useBorderPadding

    protected boolean useBorderPadding

Adjusts the cell contents to compensate for border widths. Note that this only has an effect when rendered to PDF.

#### groupChange

    protected boolean groupChange

Does this `Cell` force a group change?

### Constructor Detail

#### Cell

    public Cell()

Constructs an empty `Cell`.

#### Cell

    public Cell(boolean dummy)

Constructs an empty `Cell` (for internal use only).

Parameters:
  `dummy` - a dummy value

#### Cell

    public Cell(java.lang.String content)

Constructs a `Cell` with a certain content.

The `String` will be converted into a `Paragraph`.

Parameters:
  `content` - a `String`

#### Cell

    public Cell(Element element)
         throws BadElementException

Constructs a `Cell` with a certain `Element`.

if the element is a `ListItem`, `Row` or `Cell`, an exception will be thrown.

Parameters:
  `element` - the element
Throws:
  `BadElementException` - when the creator was called with a `ListItem`, `Row` or `Cell`

### Method Detail

#### process

    public boolean process(ElementListener listener)

Processes the element by adding it (or the different parts) to an `ElementListener`.

Specified by:
  `process` in interface `Element`
Overrides:
  `process` in class `Rectangle`
Parameters:
  `listener` - an `ElementListener`
Returns:
  `true` if the element was processed successfully

#### type

    public int type()

Gets the type of the text element.

Specified by:
  `type` in interface `Element`
Overrides:
  `type` in class `Rectangle`
Returns:
  a type

#### getChunks

    public java.util.ArrayList getChunks()

Gets all the chunks in this element.

Specified by:
  `getChunks` in interface `Element`
Overrides:
  `getChunks` in class `Rectangle`
Returns:
  an `ArrayList`

#### getHorizontalAlignment

    public int getHorizontalAlignment()

Gets the horizontal alignment.

Returns:
  a value

#### setHorizontalAlignment

    public void setHorizontalAlignment(int value)

Sets the horizontal alignment.

Parameters:
  `value` - the new value

#### setHorizontalAlignment

    public void setHorizontalAlignment(java.lang.String alignment)

Sets the alignment of this cell. This methods allows you to set the alignment as a String.

Parameters:
  `alignment` - the new alignment as a `String`

#### getVerticalAlignment

    public int getVerticalAlignment()

Gets the vertical alignment.

Returns:
  a value

#### setVerticalAlignment

    public void setVerticalAlignment(int value)

Sets the vertical alignment.

Parameters:
  `value` - the new value

#### setVerticalAlignment

    public void setVerticalAlignment(java.lang.String alignment)

Sets the alignment of this paragraph.

Parameters:
  `alignment` - the new alignment as a `String`

#### setWidth

    public void setWidth(float value)

Sets the width.

Parameters:
  `value` - the new value

#### setWidth

    public void setWidth(java.lang.String value)

Sets the width. It can be an absolute value "100" or a percentage "20%"

Parameters:
  `value` - the new value

#### getWidth

    public float getWidth()

Gets the width.

Overrides:
  `getWidth` in class `Rectangle`
Returns:
  the width

#### getWidthAsString

    public java.lang.String getWidthAsString()

Gets the width as a String.

Returns:
  a value

#### setColspan

    public void setColspan(int value)

Sets the colspan.

Parameters:
  `value` - the new value

#### getColspan

    public int getColspan()

Gets the colspan.

Returns:
  a value

#### setRowspan

    public void setRowspan(int value)

Sets the rowspan.

Parameters:
  `value` - the new value

#### getRowspan

    public int getRowspan()

Gets the rowspan.

Returns:
  a value

#### setLeading

    public void setLeading(float value)

Sets the leading.

Parameters:
  `value` - the new value

#### getLeading

    public float getLeading()

Gets the leading.

Returns:
  a value

#### setHeader

    public void setHeader(boolean value)

Sets header.

Parameters:
  `value` - the new value

#### isHeader

    public boolean isHeader()

Is this `Cell` a header?

Returns:
  a value

#### setMaxLines

    public void setMaxLines(int value)

Setter for maxLines

Parameters:
  `value` - the maximum number of lines

#### getMaxLines

    public int getMaxLines()

Getter for maxLines

Returns:
  the maxLines value

#### setShowTruncation

    public void setShowTruncation(java.lang.String value)

Setter for showTruncation

Parameters:
  `value` - Can be null for avoiding marking the truncation.

#### getShowTruncation

    public java.lang.String getShowTruncation()

Getter for showTruncation

Returns:
  the showTruncation value

#### setUseAscender

    public void setUseAscender(boolean use)

Sets the value of useAscender.

Parameters:
  `use` - use ascender height if true

#### isUseAscender

    public boolean isUseAscender()

Gets the value of useAscender

Returns:
  useAscender

#### setUseDescender

    public void setUseDescender(boolean use)

Sets the value of useDescender.

Parameters:
  `use` - use descender height if true

#### isUseDescender

    public boolean isUseDescender()

gets the value of useDescender

Returns:
  useDescender

#### setUseBorderPadding

    public void setUseBorderPadding(boolean use)

Sets the value of useBorderPadding.

Parameters:
  `use` - adjust layout for borders if true

#### isUseBorderPadding

    public boolean isUseBorderPadding()

Gets the value of useBorderPadding.

Returns:
  useBorderPadding

#### getGroupChange

    public boolean getGroupChange()

Does this `Cell` force a group change?

Returns:
  a value

#### setGroupChange

    public void setGroupChange(boolean value)

Sets group change.

Parameters:
  `value` - the new value

#### size

    public int size()

Gets the number of `Element`s in the Cell.

Returns:
  a `size`.

#### getElements

    public java.util.Iterator getElements()

Gets an iterator of `Element`s.

Returns:
  an `Iterator`.

#### clear

    public void clear()

Clears all the `Element`s of this `Cell`.

#### isEmpty

    public boolean isEmpty()

Checks if the `Cell` is empty.

Returns:
  `false` if there are non-empty `Element`s in the `Cell`.

#### fill

    void fill()

Makes sure there is at least 1 object in the Cell. Otherwise it might not be shown in the table.

#### isTable

    public boolean isTable()

Checks if this `Cell` is a placeholder for a (nested) table.

Returns:
  true if the only element in this cell is a table

#### addElement

    public void addElement(Element element)
                    throws BadElementException

Adds an element to this `Cell`.

Remark: you can't add `ListItem`s, `Row`s, `Cell`s, `JPEG`s, `GIF`s or `PNG`s to a `Cell`.

Parameters:
  `element` - The `Element` to add
Throws:
  `BadElementException` - if the method was called with a `ListItem`, `Row` or `Cell`

#### add

    public boolean add(java.lang.Object o)

Add an `Object` to this cell.

Specified by:
  `add` in interface `TextElementArray`
Parameters:
  `o` - the object to add
Returns:
  always `true`

#### getDummyCell

    private static Cell getDummyCell()

Get dummy cell used when merging inner tables.

Returns:
  a cell with colspan 3 and no border

#### createPdfPCell

    public PdfPCell createPdfPCell()
                            throws BadElementException

Creates a PdfPCell based on this Cell object.

Returns:
  a PdfPCell
Throws:
  `BadElementException`

#### getTop

    public float getTop()

This method throws an `UnsupportedOperationException`.

Overrides:
  `getTop` in class `Rectangle`
Returns:
  NA

#### getBottom

    public float getBottom()

This method throws an `UnsupportedOperationException`.

Overrides:
  `getBottom` in class `Rectangle`
Returns:
  NA

#### getLeft

    public float getLeft()

This method throws an `UnsupportedOperationException`.

Overrides:
  `getLeft` in class `Rectangle`
Returns:
  NA

#### getRight

    public float getRight()

This method throws an `UnsupportedOperationException`.

Overrides:
  `getRight` in class `Rectangle`
Returns:
  NA

#### top

    public float top(int margin)

This method throws an `UnsupportedOperationException`.

Parameters:
  `margin` -
Returns:
  NA

#### bottom

    public float bottom(int margin)

This method throws an `UnsupportedOperationException`.

Parameters:
  `margin` -
Returns:
  NA

#### left

    public float left(int margin)

This method throws an `UnsupportedOperationException`.

Parameters:
  `margin` -
Returns:
  NA

#### right

    public float right(int margin)

This method throws an `UnsupportedOperationException`.

Parameters:
  `margin` - NA
Returns:
  NA

#### setTop

    public void setTop(int value)

This method throws an `UnsupportedOperationException`.

Parameters:
  `value` - NA

#### setBottom

    public void setBottom(int value)

This method throws an `UnsupportedOperationException`.

Parameters:
  `value` - NA

#### setLeft

    public void setLeft(int value)

This method throws an `UnsupportedOperationException`.

Parameters:
  `value` - NA

#### setRight

    public void setRight(int value)

This method throws an `UnsupportedOperationException`.

Parameters:
  `value` - NA