public void itemsAdvanced(ReportEvent event) {
// if this is a preparerun, nothing gets printed and so no font change is required.
if (event.getState().isPrepareRun())
{
return;
}
// Try to get the name of the font to be set.
// If the name is null, return without an excpetion, just do nothing.
final String fontname = (String) event.getDataRow().get(1);
if (fontname == null)
{
return;
}
// Lookup the element by name. If there no element found, the getElement function
// returns null, so we have to check this case.
final Element e = event.getReport().getItemBand().getElement(getElement());
// set the font if an element was found.
if (e != null && (e instanceof TextElement))
{
final TextElement tx = (TextElement) e;
tx.getStyle().setFontDefinitionProperty(
new FontDefinition(new Font(fontname, Font.PLAIN, 10)));
}
}
Before an ItemBand is printed, the report generator will call itemsAdvanced
for all functions in the function collection. This is the right place to alter
the font of the element defined in the "element" property, so that every ItemBand
has the font set, that is defined in the data model. |