Working with tables is actually no different from any other part of the library The principles and programming model apply to tables as they do to any other type of element. This section provides the specifics about working with dynamic tables.
To use a table, create a DhTable object, add DhRow objects to that, and then add DhCell objects to the rows. The following are the rules for table usage.
While this may seem restrictive, you can easily create a simple container that emulates a gridbag by using the code in the following example.
import com.ms.wfc.html.*; public class GridBag extends DhTable { int cols; int currCol; DhRow currRow; public GridBag(int cols) { this.cols = cols; this.currCol = cols; } public void add(DhElement e) { if( ++this.currCol >= cols ) { this.currRow = new DhRow(); super.add(currRow); this.currCol = 0; } DhCell c = new DhCell(); c.add(e); this.currRow.add( c ); } }
To use this GridBag class, you just set the number of rows and columns (they must be the same with this implementation) and then assign elements to cells. The following is an example of the code in your DhDocument-derived class that uses this GridBag.
Example
protected void initForm() { GridBag myTable = new GridBag(5); for (int i = 0; i < 25; ++i){ myTable.add(new DhText("" + i)); setNewElements( new DhElement[] { myTable } ); } }
One of the most powerful uses of the library is the combination of tables and Style objects. This combination enables you to create custom report generators that are powerful, professional looking, and easy to code.