简体   繁体   中英

How to make and connect the Java swing program that has uploading, setting header and footer report

I am developing an application in Java Swing . I am using JasperReports and iReport in my application.

I have successfully made the connection between JasperReports and database and also loaded the jrxml file.

My Question is that after completing the development of my application I want that applications's users be able to set their logo, can change their header and footers. One way i can do this is by creating a User Interface that is a JFrame which has uploading image option + change the headers and footers of the report. But how do I connect my JFrame components with a JR report so that changes made in components of my JFrame should get reflected in report?

这是我要进行选择或更改的框架,应该反映在Jasper Report中

I'm assuming that the meaning of "upload" is saving the image in the hard disk of server computer in a specific path then saving this path in the database.

  1. Convert the uploaded image into InputStream

     String imgPath = "[path_of_uploaded_image_here]"; BufferedImage image = ImageIO.read(new File(imgPath)); ByteArrayOutputStream os = new ByteArrayOutputStream(); ImageIO.write(image, "gif", os); InputStream is = new ByteArrayInputStream(os.toByteArray()); 
  2. Pass the converted image as a parameter to the jasperreport.(here the param name is ENTITY_IMAGE)

  3. Inside the iReport, create a parameter. Data type of this parameter should be java.io.InputStream

  4. Drag an image. Go the image properties. Under the image properties, change the value of Expression Class as java.io.InputStream then the Image Expression as $P{ENTITY_IMAGE}.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM