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. A table, however, is such a powerful and popular element that it is worth discussing.
To use a table you create a DhTable object, add DhRow objects to that and then add DhCell objects to the rows. Here are the rules regarding table usage:
While this may seem restrictive, you can easily do a simplistic container that emulates a gridbag with the following code:
import com.ms.wd.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 );
}
}
One of the most powerful uses of the library is the combination of tables and style objects. This combination allows you to create powerful, well looking, and easy to code custom report generators.