I have created a small report using jasper reports and I previewed it using the jasper viewer as below,
con = JDBCConnectionPool.getInstance().checkOut();
String fileName = getClass().getClassLoader().getResource("com/bio/ofm/mnu/views/reports/jasperReports/repAuditReport.jrxml").getFile();
JasperReport report = JasperCompileManager.compileReport(fileName);
JasperPrint print = JasperFillManager.fillReport(report, null, con);
JasperViewer viewer = new JasperViewer(print);
viewer.setVisible(true);
But I need to show this report in a JPanel so, I tried as,
JasperViewer.setDefaultLookAndFeelDecorated(true);
JRViewer jrv = new JRViewer(print);
jrv.setPreferredSize(new Dimension(getSize()));
JScrollPane reportScroll = new JScrollPane(jrv);
panel1.add(reportScroll);
but the report is not showing as I expected, please explain what is the correct way to add a jasper preview in to a JPanel.
JasperViewer extends JFrame, and you don't want to add a JFrame to a JPanel. You could perhaps add the JasperViewer's contentPane to the JPanel. The other issues I've discussed in a comment still remain unresolved:
What layout manager is panel1 using? Are you adding the JScrollPane to the JPanel after the GUI has been displayed? If so, do you call revalidate() and repaint() on the JPanel after the addition?