Programming using the BIRT Reporting APIs : Programming the structure of a report design : Using a report item in a report design : How to add a grid item and label item to a report design
 
How to add a grid item and label item to a report design
The code sample in Listing 12‑24 creates a grid item and adds a label item to one of the cells in the grid. An application can create any other report item in a similar manner. The variable, design, is a ReportDesignHandle object.
Listing 12‑24 Adding a container item to the body slot
// Instantiate an element factory.
ElementFactory factory = design.getElementFactory( );
try {
// Create a grid element with 2 columns and 1 row.
GridHandle grid = factory.newGridItem( "New grid", 2, 1 );
// Set a simple property on the grid, the width.
grid.setWidth( "50%" );
// Create a new label and set its properties.
LabelHandle label = factory.newLabel( "Hello Label" );
label.setText( "Hello, world!" );
 
// Get the first row of the grid.
RowHandle row = ( RowHandle ) grid.getRows( ).get( 0 );
// Add the label to the second cell in the row.
CellHandle cell = ( CellHandle ) row.getCells( ).get( 1 );
cell.getContent( ).add( label );
 
// Get the body slot. Add the grid to the end of the slot.
design.getBody( ).add( grid );
} catch ( Exception e ) {
// Handle any exception
}