com.ibm.as400.util.html

Class HTMLTable

  • All Implemented Interfaces:
    HTMLConstants, HTMLTagElement, java.io.Serializable


    public class HTMLTable
    extends HTMLTagAttributes
    implements HTMLConstants, java.io.Serializable
    The HTMLTable class represents an HTML table tag.

    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:

    • ElementEvent - The events fired are:
      • elementAdded
      • elementChanged
      • elementRemoved
    • PropertyChangeEvent
    • VetoableChangeEvent
    See Also:
    HTMLTableRow, HTMLTableCell, HTMLTableHeader, HTMLTableCaption, Serialized Form
    • Constructor Detail

      • HTMLTable

        public HTMLTable()
        Constructs a default HTMLTable object.
      • HTMLTable

        public HTMLTable(HTMLTableRow[] rows)
        Constructs an HTMLTable object with the specified rows.
        Parameters:
        rows - An array of HTMLTableRow objects.
    • Method Detail

      • addColumn

        public void addColumn(HTMLTableCell[] column)
        Adds a column to the end of the table.
        Parameters:
        column - An array of HTMLTableCell objects containing the data.
      • addColumnHeader

        public void addColumnHeader(java.lang.String header)
        Adds a column header to the end of the table header.
        Parameters:
        header - The column header.
      • addColumnHeader

        public void addColumnHeader(HTMLTableHeader header)
        Adds a column header to the end of the table header.
        Parameters:
        header - The column header.
      • addRow

        public void addRow(HTMLTableRow row)
        Adds a row to the end of the table.
        Parameters:
        row - An HTMLTableRow object containing the row data.
      • addVetoableChangeListener

        public void addVetoableChangeListener(java.beans.VetoableChangeListener listener)
        Adds the VetoableChangeListener. The specified VetoableChangeListener's vetoableChange method is called each time the value of any constrained property is changed.
        Parameters:
        listener - The VetoableChangeListener.
        See Also:
        removeVetoableChangeListener(java.beans.VetoableChangeListener)
      • getAlignment

        public java.lang.String getAlignment()
        Returns the table horizontal alignment.
        Returns:
        The table alignment.
      • getBorderWidth

        public int getBorderWidth()
        Returns the border width. A value of zero indicates no border.
        Returns:
        The border width.
      • getCaption

        public HTMLTableCaption getCaption()
        Returns the table caption.
        Returns:
        An HTMLTableCaption object containing the table caption.
      • getCellPadding

        public int getCellPadding()
        Returns the global table cell padding. The cell padding is the spacing between data in a table cell and the border of the cell.
        Returns:
        The cell padding.
      • getCellSpacing

        public int getCellSpacing()
        Returns the global table cell spacing. The cell spacing is the spacing between the cells.
        Returns:
        The cell spacing.
      • getColumn

        public HTMLTableCell[] getColumn(int columnIndex)
        Returns a column in the table as an array of HTMLTableCell objects.
        Parameters:
        columnIndex - The index of the table column (0-based).
        Returns:
        An array of HTMLTableCell objects.
      • getColumnHeader

        public HTMLTableHeader getColumnHeader(int columnIndex)
        Returns the table header tag for the specified columnIndex.
        Parameters:
        columnIndex - The index of the column header (0-based).
        Returns:
        The table header tag.
      • getDirection

        public java.lang.String getDirection()
        Returns the direction of the text interpretation.
        Returns:
        The direction of the text.
      • getHeader

        public HTMLTableHeader[] getHeader()
        Returns the table column header tags.
        Returns:
        The header tags or null if the header is not set.
      • getHeaderTag

        public java.lang.String getHeaderTag()
        Returns the HTML tag for the table column headers.
        Returns:
        The HTML table header tag or an empty String if the header is not set.
      • getLanguage

        public java.lang.String getLanguage()
        Returns the language of the caption.
        Returns:
        The language of the caption.
      • getRowCount

        public int getRowCount()
        Returns the number of rows in the table.
        Returns:
        The number of rows.
      • getRow

        public HTMLTableRow getRow(int rowIndex)
        Returns the HTMLTableRow object for the specified rowIndex.
        Parameters:
        rowIndex - The index of the table row (0-based).
        Returns:
        The table row object.
      • getTag

        public java.lang.String getTag()
        Returns the HTML table tag.
        Specified by:
        getTag in interface HTMLTagElement
        Returns:
        The tag.
      • getFOTag

        public java.lang.String getFOTag()
        Returns the XSL-FO table tag. The language, cell spacing, and table width attributes are not supported in XSL-FO.
        Specified by:
        getFOTag in interface HTMLTagElement
        Returns:
        The tag.
      • getWidth

        public int getWidth()
        Returns the table width in pixels or percent.
        Returns:
        The table width.
        See Also:
        isWidthInPercent()
      • isHeaderInUse

        public boolean isHeaderInUse()
        Indicates if the table column header should be used.
        Returns:
        true if column header should be used; false otherwise.
      • isWidthInPercent

        public boolean isWidthInPercent()
        Indicates if the table width is in percent or pixels.
        Returns:
        true if percent, false if pixels.
        See Also:
        getWidth()
      • isUseFO

        public boolean isUseFO()
        Returns if Formatting Object tags are outputted. The default value is false.
        Returns:
        true if the output generated is an XSL formatting object, false if the output generated is HTML.
      • removeAllRows

        public void removeAllRows()
        Removes all the rows from the table.
      • removeColumn

        public void removeColumn(int columnIndex)
        Removes a column from the table at the specified columnIndex. If the column header exists it is also removed.
        Parameters:
        columnIndex - The index of the column to be removed (0-based).
      • removeColumnHeader

        public void removeColumnHeader(int columnIndex)
        Removes the column header at the specified columnIndex.
        Parameters:
        columnIndex - The index of the column header to be removed (0-based).
      • removeColumnHeader

        public void removeColumnHeader(HTMLTableHeader header)
        Removes a column header from the table header.
        Parameters:
        header - The column header.
      • removeRow

        public void removeRow(HTMLTableRow row)
        Removes the row from the table.
        Parameters:
        row - An HTMLTableRow object containing the row data.
      • removeRow

        public void removeRow(int rowIndex)
        Removes the row at the specified rowIndex.
        Parameters:
        rowIndex - The index of the row to be removed (0-based).
      • removeVetoableChangeListener

        public void removeVetoableChangeListener(java.beans.VetoableChangeListener listener)
        Removes the VetoableChangeListener from the internal list. If the VetoableChangeListener is not on the list, nothing is done.
        Parameters:
        listener - The VetoableChangeListener.
        See Also:
        addVetoableChangeListener(java.beans.VetoableChangeListener)
      • setAlignment

        public void setAlignment(java.lang.String alignment)
                          throws java.beans.PropertyVetoException
        Sets the table horizontal alignment. The default value is LEFT.
        Parameters:
        alignment - The table alignment. One of the following constants defined in HTMLConstants: LEFT, CENTER, or RIGHT.
        Throws:
        java.beans.PropertyVetoException - If the change is vetoed.
        See Also:
        HTMLConstants
      • setBorderWidth

        public void setBorderWidth(int borderWidth)
                            throws java.beans.PropertyVetoException
        Sets the border width in pixels. A value of zero indicates no border. The default value is zero.
        Parameters:
        borderWidth - The border width.
        Throws:
        java.beans.PropertyVetoException - If the change is vetoed.
      • setCaption

        public void setCaption(java.lang.String caption)
                        throws java.beans.PropertyVetoException
        Sets the table caption.
        Parameters:
        caption - The table caption.
        Throws:
        java.beans.PropertyVetoException - If the change is vetoed.
      • setCaption

        public void setCaption(HTMLTableCaption caption)
                        throws java.beans.PropertyVetoException
        Sets the table caption.
        Parameters:
        caption - An HTMLTableCaption object containing the table caption.
        Throws:
        java.beans.PropertyVetoException - If the change is vetoed.
      • setCellPadding

        public void setCellPadding(int cellPadding)
                            throws java.beans.PropertyVetoException
        Sets the global table cell padding. The cell padding is the spacing between data in a table cell and the border of the cell. The default value is -1 (browser default used).
        Parameters:
        cellPadding - The cell padding.
        Throws:
        java.beans.PropertyVetoException - If the change is vetoed.
      • setCellSpacing

        public void setCellSpacing(int cellSpacing)
                            throws java.beans.PropertyVetoException
        Sets the global table cell spacing. The cell spacing is the spacing between the cells. The default value is -1 (browser default used).
        Parameters:
        cellSpacing - The cell spacing.
        Throws:
        java.beans.PropertyVetoException - If the change is vetoed.
      • setColumn

        public void setColumn(HTMLTableCell[] column,
                     int columnIndex)
        Sets a column in the table at the specified columnIndex.
        Parameters:
        column - An array of HTMLTableCell objects containing the column data.
        columnIndex - The index of the column (0-based).
      • setColumnHeader

        public void setColumnHeader(java.lang.String header,
                           int columnIndex)
                             throws java.beans.PropertyVetoException
        Sets the table column header tag.
        Parameters:
        header - The table column header.
        columnIndex - The index of the column to be changed (0-based).
        Throws:
        java.beans.PropertyVetoException - If the change is vetoed.
      • setColumnHeader

        public void setColumnHeader(HTMLTableHeader header,
                           int columnIndex)
                             throws java.beans.PropertyVetoException
        Sets the table column header tag at the specified columnIndex.
        Parameters:
        header - The table column header.
        columnIndex - The index of the column to be changed (0-based).
        Throws:
        java.beans.PropertyVetoException - If the change is vetoed.
      • setDirection

        public void setDirection(java.lang.String dir)
                          throws java.beans.PropertyVetoException
        Sets the direction of the text interpretation.
        Parameters:
        dir - The direction. One of the following constants defined in HTMLConstants: LTR or RTL.
        Throws:
        java.beans.PropertyVetoException - If a change is vetoed.
        See Also:
        HTMLConstants
      • setHeader

        public void setHeader(HTMLTableHeader[] header)
                       throws java.beans.PropertyVetoException
        Sets the table column headers.
        Parameters:
        header - The column headers.
        Throws:
        java.beans.PropertyVetoException - If the change is vetoed.
        See Also:
        setHeaderInUse(boolean)
      • setHeader

        public void setHeader(java.lang.String[] header)
                       throws java.beans.PropertyVetoException
        Sets the table column headers.
        Parameters:
        header - The column headers.
        Throws:
        java.beans.PropertyVetoException - If the change is vetoed.
      • setHeaderInUse

        public void setHeaderInUse(boolean headerInUse)
                            throws java.beans.PropertyVetoException
        Sets if table column headers should be used. The default value is true.
        Parameters:
        headerInUse - true if the column headers should be used; false otherwise.
        Throws:
        java.beans.PropertyVetoException - If the change is vetoed.
      • setLanguage

        public void setLanguage(java.lang.String lang)
                         throws java.beans.PropertyVetoException
        Sets the language of the caption.
        Parameters:
        lang - The language. Example language tags include: en and en-US.
        Throws:
        java.beans.PropertyVetoException - If a change is vetoed.
      • setRow

        public void setRow(HTMLTableRow row,
                  int rowIndex)
        Sets the table row at the specified rowIndex.
        Parameters:
        row - An HTMLTableRow object with the row data.
        rowIndex - The index of the row (0-based).
      • setWidth

        public void setWidth(int width)
                      throws java.beans.PropertyVetoException
        Sets the table width. The default width unit is pixels.
        Parameters:
        width - The table width.
        Throws:
        java.beans.PropertyVetoException - If the change is vetoed.
        See Also:
        setWidthInPercent(boolean)
      • setWidth

        public void setWidth(int width,
                    boolean widthInPercent)
                      throws java.beans.PropertyVetoException
        Sets the table width in percent or pixels.
        Parameters:
        width - The table width.
        widthInPercent - true if width is specified as a percent; false if width is specified in pixels.
        Throws:
        java.beans.PropertyVetoException - If the change is vetoed.
      • setWidthInPercent

        public void setWidthInPercent(boolean widthInPercent)
                               throws java.beans.PropertyVetoException
        Sets the table width unit in percent or pixels. The default is false.
        Parameters:
        widthInPercent - true if width is specified as a percent; false if width is specified in pixels.
        Throws:
        java.beans.PropertyVetoException - If the change is vetoed.
        See Also:
        setWidth(int)
      • setUseFO

        public void setUseFO(boolean useFO)
        Sets if Formatting Object tags should be used. The default value is false.
        Parameters:
        useFO - - true if output generated is an XSL formatting object, false if the output generated is HTML.
      • toString

        public java.lang.String toString()
        Returns the HTML table tag.
        Overrides:
        toString in class java.lang.Object
        Returns:
        The tag.