13.07.2015 Views

iReport Ultimate Guide - Nimsoft Library

iReport Ultimate Guide - Nimsoft Library

iReport Ultimate Guide - Nimsoft Library

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>iReport</strong> <strong>Ultimate</strong> <strong>Guide</strong>Figure 5-19An image element rendered using a custom JRRenderable objectWhat we did is to set the Image Element Expression to:new com.jaspersoft.ireport.samples.CustomImageRenderer()and the Image Expression Class to net.sf.jasperreports.engine.JRRenderable. We have not passed anyargument to our implementation class, but this is possible, allowing the final user to pass to the renderer extra information toproduce the image.With a similar approach it is possible to modify an image (rotate, transform and so on), add a watermark to an image or eveninsert into the report a Swing component.Code Example 5-2 shows how to print a JTable. The code is not much different from what we have seen in the previoussample; the idea is to force the component to paint itself into the provided Graphics2D. The result is incredibly good and thereis no loss of quality when using the internal UR preview component (see Figure 5-20) or when exporting to PDF.. Code Example 5-2 Printing a JTablepackage com.jaspersoft.ireport.samples;import java.awt.Graphics2D;import java.awt.geom.AffineTransform;import java.awt.geom.Rectangle2D;import javax.swing.JTable;import javax.swing.table.DefaultTableModel;import javax.swing.table.JTableHeader;import net.sf.jasperreports.engine.JRAbstractSvgRenderer;import net.sf.jasperreports.engine.JRException;/**** @author gtoffoli*/public class SwingComponentRenderer extends JRAbstractSvgRenderer {public void render(Graphics2D g2d, Rectangle2D rect) throws JRException {/ Save the Graphics2D affine transformAffineTransform trans = g2d.getTransform();82

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!