ibm-information-center/dist/eclipse/plugins/i5OS.ic.rzahh_5.4.0.1/htmtblex.htm

127 lines
5.6 KiB
HTML
Raw Normal View History

2024-04-02 14:02:31 +00:00
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en-us" xml:lang="en-us">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="security" content="public" />
<meta name="Robots" content="index,follow" />
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
<meta name="DC.Type" content="reference" />
<meta name="DC.Title" content="Example: Using HTMLTable classes" />
<meta name="abstract" content="" />
<meta name="description" content="" />
<meta name="copyright" content="(C) Copyright IBM Corporation 2006" />
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 2006" />
<meta name="DC.Format" content="XHTML" />
<meta name="DC.Identifier" content="htmtblex" />
<meta name="DC.Language" content="en-us" />
<!-- All rights reserved. Licensed Materials Property of IBM -->
<!-- US Government Users Restricted Rights -->
<!-- Use, duplication or disclosure restricted by -->
<!-- GSA ADP Schedule Contract with IBM Corp. -->
<link rel="stylesheet" type="text/css" href="./ibmdita.css" />
<link rel="stylesheet" type="text/css" href="./ic.css" />
<title>Example: Using HTMLTable classes</title>
</head>
<body id="htmtblex"><a name="htmtblex"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Example: Using HTMLTable classes</h1>
<div><p></p>
<div class="section"><p>The following example shows you how the HTMLTable classes work: </p>
<pre> // Create a default HTMLTable object.
HTMLTable table = new HTMLTable();
// Set the table attributes.
table.setAlignment(HTMLTable.CENTER);
table.setBorderWidth(1);
// Create a default HTMLTableCaption object and set the caption text.
HTMLTableCaption caption = new HTMLTableCaption();
caption.setElement("Customer Account Balances - January 1, 2000");
// Set the caption.
table.setCaption(caption);
// Create the table headers and add to the table.
HTMLTableHeader account_header = new HTMLTableHeader(new HTMLText("ACCOUNT"));
HTMLTableHeader name_header = new HTMLTableHeader(new HTMLText("NAME"));
HTMLTableHeader balance_header = new HTMLTableHeader(new HTMLText("BALANCE"));
table.addColumnHeader(account_header);
table.addColumnHeader(name_header);
table.addColumnHeader(balance_header);
// Add rows to the table. Each customer record represents a row in the table.
int numCols = 3;
for (int rowIndex=0; rowIndex&lt; numCustomers; rowIndex++)
{
HTMLTableRow row = new HTMLTableRow();
row.setHorizontalAlignment(HTMLTableRow.CENTER);
HTMLText account = new HTMLText(customers[rowIndex].getAccount());
HTMLText name = new HTMLText(customers[rowIndex].getName());
HTMLText balance = new HTMLText(customers[rowIndex].getBalance());
row.addColumn(new HTMLTableCell(account));
row.addColumn(new HTMLTableCell(name));
row.addColumn(new HTMLTableCell(balance));
// Add the row to the table.
table.addRow(row);
}
System.out.println(table.getTag());</pre>
<p> The Java™ code
example above generates the following HTML code: </p>
<pre> &lt;table align="center" border="1"&gt;
&lt;caption&gt;Customer Account Balances - January 1, 2000&lt;/caption&gt;
&lt;tr&gt;
&lt;th&gt;ACCOUNT&lt;/th&gt;
&lt;th&gt;NAME&lt;/th&gt;
&lt;th&gt;BALANCE&lt;/th&gt;
&lt;/tr&gt;
&lt;tr align="center"&gt;
&lt;td&gt;0000001&lt;/td&gt;
&lt;td&gt;Customer1&lt;/td&gt;
&lt;td&gt;100.00&lt;/td&gt;
&lt;/tr&gt;
&lt;tr align="center"&gt;
&lt;td&gt;0000002&lt;/td&gt;
&lt;td&gt;Customer2&lt;/td&gt;
&lt;td&gt;200.00&lt;/td&gt;
&lt;/tr&gt;
&lt;tr align="center"&gt;
&lt;td&gt;0000003&lt;/td&gt;
&lt;td&gt;Customer3&lt;/td&gt;
&lt;td&gt;550.00&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;</pre>
<p>The following table shows how the HTML code
above displays in a Web browser.</p>
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" width="100%" frame="border" border="1" rules="all"><caption>Table 1. Customer
Account Balances - January 1, 2000</caption><thead align="left"><tr><th align="center" valign="top" width="30.434782608695656%" id="d0e34">ACCOUNT</th>
<th align="center" valign="top" width="39.130434782608695%" id="d0e36">NAME</th>
<th align="center" valign="top" width="30.434782608695656%" id="d0e38">BALANCE</th>
</tr>
</thead>
<tbody><tr><td align="center" valign="top" width="30.434782608695656%" headers="d0e34 ">0000001</td>
<td align="center" valign="top" width="39.130434782608695%" headers="d0e36 ">Customer1</td>
<td align="center" valign="top" width="30.434782608695656%" headers="d0e38 ">100.00</td>
</tr>
<tr><td align="center" valign="top" width="30.434782608695656%" headers="d0e34 ">0000002</td>
<td align="center" valign="top" width="39.130434782608695%" headers="d0e36 ">Customer2</td>
<td align="center" valign="top" width="30.434782608695656%" headers="d0e38 ">200.00</td>
</tr>
<tr><td align="center" valign="top" width="30.434782608695656%" headers="d0e34 ">0000003</td>
<td align="center" valign="top" width="39.130434782608695%" headers="d0e36 ">Customer3</td>
<td align="center" valign="top" width="30.434782608695656%" headers="d0e38 ">550.00</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</body>
</html>