JAVA Reporting Tool iReport

2019-04-15 23:25发布

问题:

Can we get a reporting page which is like .Net's Crystal report using iReport? That is I need to get the report inside the frame.

回答1:

Assuming you are using Swing, here is an example how to do it.

Edit:

Try getting the JasperViewer container and add that to the main JFrame or JPanel.

Bit of a hack job but it should do the trick.

JasperDesign jd = JRXMLoader.load("FilePath"); 
JasperReport jr = JasperCompileManager.compileReport(jd);
JasperPrint jp = JasperFillManager.fillReport((jr),null,con);
// Create an instance of the JasperViewer instead of using the static call
JasperViewer viewer=new JasperViewer(jp,false);
// Get the viewers container and add that to the main frame or panel
Container container = viewer.getContentPane();
myMainJFrame.add(container);