Package com.lowagie.text
Class Cell
java.lang.Object
com.lowagie.text.Rectangle
com.lowagie.text.TableRectangle
com.lowagie.text.Cell
- All Implemented Interfaces:
WithHorizontalAlignment
,WithVerticalAlignment
,Element
,TextElementArray
public class Cell
extends TableRectangle
implements TextElementArray, WithHorizontalAlignment, WithVerticalAlignment
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:
-
Field Summary
FieldsModifier and TypeFieldDescriptionTheArrayList
ofElement
s that are part of the content of the Cell.protected int
The colspan of the cell.protected boolean
Does thisCell
force a group change?protected boolean
Is thisCell
a header?protected int
The horizontal alignment of the cell content.(package private) float
The leading of the content inside the cell.protected int
Maximum number of lines allowed in the cell.protected boolean
protected int
The rowspan of the cell.(package private) String
If a truncation happens due to the maxLines property, then this text will be added to indicate a truncation has happened.protected boolean
Indicates that the largest ascender height should be used to determine the height of the first line.protected boolean
Adjusts the cell contents to compensate for border widths.protected boolean
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
The vertical alignment of the cell content.protected float
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, offsetToTop, 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, FOOTNOTE, HEADER, IMGRAW, IMGTEMPLATE, JBIG2, JPEG, JPEG2000, KEYWORDS, LIST, LISTITEM, MARKED, MODIFICATIONDATE, MULTI_COLUMN_TEXT, PARAGRAPH, PHRASE, PRODUCER, PTABLE, RECTANGLE, ROW, SECTION, SUBJECT, TABLE, TITLE, YMARK
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
Add anObject
to this cell.void
addElement
(Element element) Adds an element to thisCell
.float
bottom
(int margin) This method throws anUnsupportedOperationException
.void
clear()
Clears all theElement
s of thisCell
.Creates a PdfPCell based on this Cell object.(package private) void
fill()
Makes sure there is at least 1 object in the Cell.float
This method throws anUnsupportedOperationException
.Gets all the chunks in this element.int
Gets the colspan.private static Cell
Get dummy cell used when merging inner tables.Gets an iterator ofElement
s.boolean
Does thisCell
force a group change?int
Gets the horizontal alignment.float
Gets the leading.float
getLeft()
This method throws anUnsupportedOperationException
.int
Getter for maxLinesfloat
getRight()
This method throws anUnsupportedOperationException
.int
Gets the rowspan.Getter for showTruncationfloat
getTop()
This method throws anUnsupportedOperationException
.int
Gets the vertical alignment.float
getWidth()
Gets the width.Gets the width as a String.boolean
isEmpty()
Checks if theCell
is empty.boolean
isHeader()
Is thisCell
a header?boolean
isTable()
Checks if thisCell
is a placeholder for a (nested) table.boolean
Gets the value of useAscenderboolean
Gets the value of useBorderPadding.boolean
gets the value of useDescenderfloat
left
(int margin) This method throws anUnsupportedOperationException
.boolean
process
(ElementListener listener) Processes the element by adding it (or the different parts) to anElementListener
.float
right
(int margin) This method throws anUnsupportedOperationException
.void
setBottom
(int value) This method throws anUnsupportedOperationException
.void
setColspan
(int value) Sets the colspan.void
setGroupChange
(boolean value) Sets group change.void
setHeader
(boolean value) Sets header.void
setHorizontalAlignment
(HorizontalAlignment alignment) Sets horizontal alignment mode.void
setLeading
(float value) Sets the leading.void
setLeft
(int value) This method throws anUnsupportedOperationException
.void
setMaxLines
(int value) Setter for maxLinesvoid
setRight
(int value) This method throws anUnsupportedOperationException
.void
setRowspan
(int value) Sets the rowspan.void
setShowTruncation
(String value) Setter for showTruncationvoid
setTop
(int value) This method throws anUnsupportedOperationException
.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
(VerticalAlignment alignment) Sets vertical alignment mode.void
setWidth
(float value) Sets the width.void
Sets the width.int
size()
Gets the number ofElement
s in the Cell.float
top
(int margin) This method throws anUnsupportedOperationException
.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, getRelativeTop, 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, setRelativeTop, setRight, setRotation, 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 Details
-
arrayList
TheArrayList
ofElement
s that are part of the content of the Cell. -
horizontalAlignment
protected int horizontalAlignmentThe horizontal alignment of the cell content. -
verticalAlignment
protected int verticalAlignmentThe vertical alignment of the cell content. -
width
protected float widthThe 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 colspanThe colspan of the cell. -
rowspan
protected int rowspanThe rowspan of the cell. -
header
protected boolean headerIs thisCell
a header? -
maxLines
protected int maxLinesMaximum 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) -
useAscender
protected boolean useAscenderIndicates 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 useDescenderIndicates 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 useBorderPaddingAdjusts the cell contents to compensate for border widths. Note that this only has an effect when rendered to PDF. -
groupChange
protected boolean groupChangeDoes thisCell
force a group change? -
leading
float leadingThe leading of the content inside the cell. -
showTruncation
String showTruncationIf 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)
-
-
Constructor Details
-
Cell
public Cell()Constructs an emptyCell
. -
Cell
public Cell(boolean dummy) Constructs an emptyCell
(for internal use only).- Parameters:
dummy
- a dummy value
-
Cell
Constructs aCell
with a certain content.The
String
will be converted into aParagraph
.- Parameters:
content
- aString
-
Cell
Constructs aCell
with a certainElement
.if the element is a
ListItem
,Row
orCell
, an exception will be thrown.- Parameters:
element
- the element- Throws:
BadElementException
- when the creator was called with aListItem
,Row
orCell
-
-
Method Details
-
getDummyCell
Get dummy cell used when merging inner tables.- Returns:
- a cell with colspan 3 and no border
-
process
Processes the element by adding it (or the different parts) to anElementListener
. -
type
public int type()Gets the type of the text element. -
getChunks
Gets all the chunks in this element. -
getHorizontalAlignment
public int getHorizontalAlignment()Gets the horizontal alignment.- Returns:
- a value
-
setHorizontalAlignment
Description copied from interface:WithHorizontalAlignment
Sets horizontal alignment mode.- Specified by:
setHorizontalAlignment
in interfaceWithHorizontalAlignment
- Parameters:
alignment
- New alignment mode. If null, current alignment must be left unchanged
-
getVerticalAlignment
public int getVerticalAlignment()Gets the vertical alignment.- Returns:
- a value
-
setVerticalAlignment
Description copied from interface:WithVerticalAlignment
Sets vertical alignment mode.- Specified by:
setVerticalAlignment
in interfaceWithVerticalAlignment
- Parameters:
alignment
- New alignment mode. If null, current alignment must be left unchanged
-
getWidth
public float getWidth()Gets the width. -
setWidth
public void setWidth(float value) Sets the width.- Parameters:
value
- the new value
-
setWidth
Sets the width. It can be an absolute value "100" or a percentage "20%"- Parameters:
value
- the new value
-
getWidthAsString
Gets the width as a String.- Returns:
- a value
-
getColspan
public int getColspan()Gets the colspan.- Returns:
- a value
-
setColspan
public void setColspan(int value) Sets the colspan.- Parameters:
value
- the new value
-
getRowspan
public int getRowspan()Gets the rowspan.- Returns:
- a value
-
setRowspan
public void setRowspan(int value) Sets the rowspan.- Parameters:
value
- the new value
-
getLeading
public float getLeading()Gets the leading.- Returns:
- a value
-
setLeading
public void setLeading(float value) Sets the leading.- Parameters:
value
- the new value
-
isHeader
public boolean isHeader()Is thisCell
a header?- Returns:
- a value
-
setHeader
public void setHeader(boolean value) Sets header.- Parameters:
value
- the new value
-
getMaxLines
public int getMaxLines()Getter for maxLines- Returns:
- the maxLines value
-
setMaxLines
public void setMaxLines(int value) Setter for maxLines- Parameters:
value
- the maximum number of lines
-
getShowTruncation
Getter for showTruncation- Returns:
- the showTruncation value
-
setShowTruncation
Setter for showTruncation- Parameters:
value
- Can be null for avoiding marking the truncation.
-
isUseAscender
public boolean isUseAscender()Gets the value of useAscender- Returns:
- useAscender
-
setUseAscender
public void setUseAscender(boolean use) Sets the value of useAscender.- Parameters:
use
- use ascender height if true
-
isUseDescender
public boolean isUseDescender()gets the value of useDescender- Returns:
- useDescender
-
setUseDescender
public void setUseDescender(boolean use) Sets the value of useDescender.- Parameters:
use
- use descender height if true
-
isUseBorderPadding
public boolean isUseBorderPadding()Gets the value of useBorderPadding.- Returns:
- useBorderPadding
-
setUseBorderPadding
public void setUseBorderPadding(boolean use) Sets the value of useBorderPadding.- Parameters:
use
- adjust layout for borders if true
-
getGroupChange
public boolean getGroupChange()Does thisCell
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 ofElement
s in the Cell.- Returns:
- a
size
.
-
getElements
Gets an iterator ofElement
s.- Returns:
- an
Iterator
.
-
clear
public void clear()Clears all theElement
s of thisCell
. -
isEmpty
public boolean isEmpty()Checks if theCell
is empty.- Returns:
false
if there are non-emptyElement
s in theCell
.
-
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 thisCell
is a placeholder for a (nested) table.- Returns:
- true if the only element in this cell is a table
-
addElement
Adds an element to thisCell
.Remark: you can't add
ListItem
s,Row
s,Cell
s,JPEG
s,GIF
s orPNG
s to aCell
.- Parameters:
element
- TheElement
to add- Throws:
BadElementException
- if the method was called with aListItem
,Row
orCell
-
add
Add anObject
to this cell.- Specified by:
add
in interfaceTextElementArray
- Parameters:
o
- the object to add- Returns:
- always
true
-
createPdfPCell
Creates a PdfPCell based on this Cell object.- Returns:
- a PdfPCell
- Throws:
BadElementException
- on error
-
getTop
public float getTop()This method throws anUnsupportedOperationException
. -
setTop
public void setTop(int value) This method throws anUnsupportedOperationException
.- Parameters:
value
- NA
-
getBottom
public float getBottom()This method throws anUnsupportedOperationException
. -
setBottom
public void setBottom(int value) This method throws anUnsupportedOperationException
.- Parameters:
value
- NA
-
getLeft
public float getLeft()This method throws anUnsupportedOperationException
. -
setLeft
public void setLeft(int value) This method throws anUnsupportedOperationException
.- Parameters:
value
- NA
-
getRight
public float getRight()This method throws anUnsupportedOperationException
. -
setRight
public void setRight(int value) This method throws anUnsupportedOperationException
.- Parameters:
value
- NA
-
top
public float top(int margin) This method throws anUnsupportedOperationException
.- Parameters:
margin
- NA- Returns:
- NA
-
bottom
public float bottom(int margin) This method throws anUnsupportedOperationException
.- Parameters:
margin
- NA- Returns:
- NA
-
left
public float left(int margin) This method throws anUnsupportedOperationException
.- Parameters:
margin
- NA- Returns:
- NA
-
right
public float right(int margin) This method throws anUnsupportedOperationException
.- Parameters:
margin
- NA- Returns:
- NA
-