public class HTMLTable extends HTMLTagAttributes implements HTMLConstants, java.io.Serializable
This example creates an HTMLTable object and sets its attributes.
HTMLTable table = new HTMLTable(); table.setAlignment(HTMLTable.CENTER); table.setHeaderInUse(false); table.setBorderWidth(1); table.setCellSpacing(2); table.setCellPadding(2); // Add the rows to the table (Assume that the HTMLTableRow objects are already created). table.addRow(row1); table.addRow(row2); table.addRow(row3); System.out.println(table.getTag());
Here is the output of the table tag:
<table border="1" align="center" cellspacing="2" cellpadding="2"> <tr> <td>row1data1</td> <td>row1data2</td> </tr> <tr> <td>row2data1</td> <td>row2data2</td> </tr> <tr> <td>row3data1</td> <td>row3data2</td> </tr> </table>
The output generated by calling getFOTag() looks like the following:
<fo:block text-align='center'> <fo:table> <fo:table-column column-width='3pt'/> <fo:table-column column-width='3pt'/> <fo:table-column column-width='3pt'/> <fo:table-body> <fo:table-row> <fo:table-cell border-style='solid' border-width='1px' padding='2px'><fo:block-container> <fo:block>row1data1</fo:block> </fo:block-container> </fo:table-cell> <fo:table-cell border-style='solid' border-width='1px' padding='2px'><fo:block-container> <fo:block>row1data2</fo:block> </fo:block-container> </fo:table-cell> </fo:table-row> <fo:table-row> <fo:table-cell border-style='solid' border-width='1px' padding='2px'><fo:block-container> <fo:block>row2data1</fo:block> </fo:block-container> </fo:table-cell> <fo:table-cell border-style='solid' border-width='1px' padding='2px'><fo:block-container> <fo:block>row2data2</fo:block> </fo:block-container> </fo:table-cell> </fo:table-row> <fo:table-row> <fo:table-cell border-style='solid' border-width='1px' padding='2px'><fo:block-container> <fo:block>row3data1</fo:block> </fo:block-container> </fo:table-cell> <fo:table-cell border-style='solid' border-width='1px' padding='2px'><fo:block-container> <fo:block>row3data2</fo:block> </fo:block-container> </fo:table-cell> </fo:table-row> </fo:table-body> </fo:table> </fo:block>
HTMLTable objects generate the following events:
ABSBOTTOM, ABSMIDDLE, BASELINE, BOTTOM, CAPITALS, CENTER, CIRCLE, DISC, JUSTIFY, LARGE_ROMAN, LEFT, LOWER_CASE, LTR, MIDDLE, NUMBERS, RIGHT, RTL, SMALL_ROMAN, SQUARE, TARGET_BLANK, TARGET_PARENT, TARGET_SELF, TARGET_TOP, TEXTTOP, TOP
Constructor and Description |
---|
HTMLTable()
Constructs a default HTMLTable object.
|
HTMLTable(HTMLTableRow[] rows)
Constructs an HTMLTable object with the specified rows.
|
Modifier and Type | Method and Description |
---|---|
void |
addColumn(HTMLTableCell[] column)
Adds a column to the end of the table.
|
void |
addColumnHeader(HTMLTableHeader header)
Adds a column header to the end of the table header.
|
void |
addColumnHeader(java.lang.String header)
Adds a column header to the end of the table header.
|
void |
addRow(HTMLTableRow row)
Adds a row to the end of the table.
|
void |
addRowListener(ElementListener listener)
Adds an ElementListener for the rows.
|
void |
addVetoableChangeListener(java.beans.VetoableChangeListener listener)
Adds the VetoableChangeListener.
|
java.lang.String |
getAlignment()
Returns the table horizontal alignment.
|
int |
getBorderWidth()
Returns the border width.
|
HTMLTableCaption |
getCaption()
Returns the table caption.
|
int |
getCellPadding()
Returns the global table cell padding.
|
int |
getCellSpacing()
Returns the global table cell spacing.
|
HTMLTableCell[] |
getColumn(int columnIndex)
Returns a column in the table as an array of HTMLTableCell objects.
|
HTMLTableHeader |
getColumnHeader(int columnIndex)
Returns the table header tag for the specified columnIndex.
|
java.lang.String |
getDirection()
Returns the direction of the text interpretation.
|
java.lang.String |
getFOTag()
Returns the XSL-FO table tag.
|
HTMLTableHeader[] |
getHeader()
Returns the table column header tags.
|
java.lang.String |
getHeaderTag()
Returns the HTML tag for the table column headers.
|
java.lang.String |
getLanguage()
Returns the language of the caption.
|
HTMLTableRow |
getRow(int rowIndex)
Returns the HTMLTableRow object for the specified rowIndex.
|
int |
getRowCount()
Returns the number of rows in the table.
|
java.lang.String |
getTag()
Returns the HTML table tag.
|
int |
getWidth()
Returns the table width in pixels or percent.
|
boolean |
isHeaderInUse()
Indicates if the table column header should be used.
|
boolean |
isUseFO()
Returns if Formatting Object tags are outputted.
|
boolean |
isWidthInPercent()
Indicates if the table width is in percent or pixels.
|
void |
removeAllRows()
Removes all the rows from the table.
|
void |
removeColumn(int columnIndex)
Removes a column from the table at the specified columnIndex.
|
void |
removeColumnHeader(HTMLTableHeader header)
Removes a column header from the table header.
|
void |
removeColumnHeader(int columnIndex)
Removes the column header at the specified columnIndex.
|
void |
removeRow(HTMLTableRow row)
Removes the row from the table.
|
void |
removeRow(int rowIndex)
Removes the row at the specified rowIndex.
|
void |
removeRowListener(ElementListener listener)
Removes this row ElementListener from the internal list.
|
void |
removeVetoableChangeListener(java.beans.VetoableChangeListener listener)
Removes the VetoableChangeListener from the internal list.
|
void |
setAlignment(java.lang.String alignment)
Sets the table horizontal alignment.
|
void |
setBorderWidth(int borderWidth)
Sets the border width in pixels.
|
void |
setCaption(HTMLTableCaption caption)
Sets the table caption.
|
void |
setCaption(java.lang.String caption)
Sets the table caption.
|
void |
setCellPadding(int cellPadding)
Sets the global table cell padding.
|
void |
setCellSpacing(int cellSpacing)
Sets the global table cell spacing.
|
void |
setColumn(HTMLTableCell[] column,
int columnIndex)
Sets a column in the table at the specified columnIndex.
|
void |
setColumnHeader(HTMLTableHeader header,
int columnIndex)
Sets the table column header tag at the specified columnIndex.
|
void |
setColumnHeader(java.lang.String header,
int columnIndex)
Sets the table column header tag.
|
void |
setDirection(java.lang.String dir)
Sets the direction of the text interpretation.
|
void |
setHeader(HTMLTableHeader[] header)
Sets the table column headers.
|
void |
setHeader(java.lang.String[] header)
Sets the table column headers.
|
void |
setHeaderInUse(boolean headerInUse)
Sets if table column headers should be used.
|
void |
setLanguage(java.lang.String lang)
Sets the language of the caption.
|
void |
setRow(HTMLTableRow row,
int rowIndex)
Sets the table row at the specified rowIndex.
|
void |
setUseFO(boolean useFO)
Sets if Formatting Object tags should be used.
|
void |
setWidth(int width)
Sets the table width.
|
void |
setWidth(int width,
boolean widthInPercent)
Sets the table width in percent or pixels.
|
void |
setWidthInPercent(boolean widthInPercent)
Sets the table width unit in percent or pixels.
|
java.lang.String |
toString()
Returns the HTML table tag.
|
addPropertyChangeListener, getAttributes, getAttributeString, removePropertyChangeListener, setAttributes
public HTMLTable()
public HTMLTable(HTMLTableRow[] rows)
rows
- An array of HTMLTableRow objects.public void addColumn(HTMLTableCell[] column)
column
- An array of HTMLTableCell objects containing the data.public void addColumnHeader(java.lang.String header)
header
- The column header.public void addColumnHeader(HTMLTableHeader header)
header
- The column header.public void addRow(HTMLTableRow row)
row
- An HTMLTableRow object containing the row data.public void addRowListener(ElementListener listener)
listener
- The ElementListener.removeRowListener(com.ibm.as400.util.html.ElementListener)
public void addVetoableChangeListener(java.beans.VetoableChangeListener listener)
listener
- The VetoableChangeListener.removeVetoableChangeListener(java.beans.VetoableChangeListener)
public java.lang.String getAlignment()
public int getBorderWidth()
public HTMLTableCaption getCaption()
public int getCellPadding()
public int getCellSpacing()
public HTMLTableCell[] getColumn(int columnIndex)
columnIndex
- The index of the table column (0-based).public HTMLTableHeader getColumnHeader(int columnIndex)
columnIndex
- The index of the column header (0-based).public java.lang.String getDirection()
public HTMLTableHeader[] getHeader()
public java.lang.String getHeaderTag()
public java.lang.String getLanguage()
public int getRowCount()
public HTMLTableRow getRow(int rowIndex)
rowIndex
- The index of the table row (0-based).public java.lang.String getTag()
getTag
in interface HTMLTagElement
public java.lang.String getFOTag()
getFOTag
in interface HTMLTagElement
public int getWidth()
isWidthInPercent()
public boolean isHeaderInUse()
public boolean isWidthInPercent()
getWidth()
public boolean isUseFO()
public void removeAllRows()
public void removeColumn(int columnIndex)
columnIndex
- The index of the column to be removed (0-based).public void removeColumnHeader(int columnIndex)
columnIndex
- The index of the column header to be removed (0-based).public void removeColumnHeader(HTMLTableHeader header)
header
- The column header.public void removeRow(HTMLTableRow row)
row
- An HTMLTableRow object containing the row data.public void removeRow(int rowIndex)
rowIndex
- The index of the row to be removed (0-based).public void removeRowListener(ElementListener listener)
listener
- The ElementListener.addRowListener(com.ibm.as400.util.html.ElementListener)
public void removeVetoableChangeListener(java.beans.VetoableChangeListener listener)
listener
- The VetoableChangeListener.addVetoableChangeListener(java.beans.VetoableChangeListener)
public void setAlignment(java.lang.String alignment) throws java.beans.PropertyVetoException
alignment
- The table alignment. One of the following constants
defined in HTMLConstants: LEFT, CENTER, or RIGHT.java.beans.PropertyVetoException
- If the change is vetoed.HTMLConstants
public void setBorderWidth(int borderWidth) throws java.beans.PropertyVetoException
borderWidth
- The border width.java.beans.PropertyVetoException
- If the change is vetoed.public void setCaption(java.lang.String caption) throws java.beans.PropertyVetoException
caption
- The table caption.java.beans.PropertyVetoException
- If the change is vetoed.public void setCaption(HTMLTableCaption caption) throws java.beans.PropertyVetoException
caption
- An HTMLTableCaption object containing the table caption.java.beans.PropertyVetoException
- If the change is vetoed.public void setCellPadding(int cellPadding) throws java.beans.PropertyVetoException
cellPadding
- The cell padding.java.beans.PropertyVetoException
- If the change is vetoed.public void setCellSpacing(int cellSpacing) throws java.beans.PropertyVetoException
cellSpacing
- The cell spacing.java.beans.PropertyVetoException
- If the change is vetoed.public void setColumn(HTMLTableCell[] column, int columnIndex)
column
- An array of HTMLTableCell objects containing the column data.columnIndex
- The index of the column (0-based).public void setColumnHeader(java.lang.String header, int columnIndex) throws java.beans.PropertyVetoException
header
- The table column header.columnIndex
- The index of the column to be changed (0-based).java.beans.PropertyVetoException
- If the change is vetoed.public void setColumnHeader(HTMLTableHeader header, int columnIndex) throws java.beans.PropertyVetoException
header
- The table column header.columnIndex
- The index of the column to be changed (0-based).java.beans.PropertyVetoException
- If the change is vetoed.public void setDirection(java.lang.String dir) throws java.beans.PropertyVetoException
dir
- The direction. One of the following constants
defined in HTMLConstants: LTR or RTL.java.beans.PropertyVetoException
- If a change is vetoed.HTMLConstants
public void setHeader(HTMLTableHeader[] header) throws java.beans.PropertyVetoException
header
- The column headers.java.beans.PropertyVetoException
- If the change is vetoed.setHeaderInUse(boolean)
public void setHeader(java.lang.String[] header) throws java.beans.PropertyVetoException
header
- The column headers.java.beans.PropertyVetoException
- If the change is vetoed.public void setHeaderInUse(boolean headerInUse) throws java.beans.PropertyVetoException
headerInUse
- true if the column headers should be used; false otherwise.java.beans.PropertyVetoException
- If the change is vetoed.public void setLanguage(java.lang.String lang) throws java.beans.PropertyVetoException
lang
- The language. Example language tags include:
en and en-US.java.beans.PropertyVetoException
- If a change is vetoed.public void setRow(HTMLTableRow row, int rowIndex)
row
- An HTMLTableRow object with the row data.rowIndex
- The index of the row (0-based).public void setWidth(int width) throws java.beans.PropertyVetoException
width
- The table width.java.beans.PropertyVetoException
- If the change is vetoed.setWidthInPercent(boolean)
public void setWidth(int width, boolean widthInPercent) throws java.beans.PropertyVetoException
width
- The table width.widthInPercent
- true if width is specified as a percent; false if width is specified in pixels.java.beans.PropertyVetoException
- If the change is vetoed.public void setWidthInPercent(boolean widthInPercent) throws java.beans.PropertyVetoException
widthInPercent
- true if width is specified as a percent; false if width is specified in pixels.java.beans.PropertyVetoException
- If the change is vetoed.setWidth(int)
public void setUseFO(boolean useFO)
useFO
- - true if output generated is an XSL formatting object, false if the output generated is HTML.public java.lang.String toString()
toString
in class java.lang.Object