I want to display JasperReports 's report on jpanel using JRViewer.
In my application(as shown in above image), i have one jcombobox and a jbutton . i have multiple names of report in the jcombobox and on click of the jbutton i want to show the report in jrviewer. when i click the button for the first time it works button when i click the button after selecting other report name from combobox it is not working.
below is the code i am using
reportPanel = new JPanel();
reportPanel.setBackground(Color.white);
JScrollPane scrollPane = new JScrollPane(reportPanel);
scrollPane.setBounds(20, 150,dim.width-60, 370);
mainPanel.add(scrollPane);
String pathUrl = System.getProperty("user.dir");
String district_cd = getKeyForValue(districtMap, districtCombo.getSelectedItem().toString());
String jasper_name = getKeyForValue(reportMap, reportCombo.getSelectedItem().toString());
String filename = FilenameUtils.removeExtension(jasper_name);
Map reportParameter = new HashMap();
reportParameter.put("district_cd", district_cd);
JasperReport report = (JasperReport) JRLoader.loadObject(pathUrl+"//"+jasper_name);
JasperPrint jasperPrint = JasperFillManager.fillReport(report,reportParameter,patchConnection);
JRViewer jrviewer = new JRViewer(jasperPrint);
reportPanel.setLayout(new BorderLayout());
reportPanel.add(jrviewer);
reportPanel.revalidate();
reportPanel.repaint(50L);
mainPanel.revalidate();
mainPanel.repaint(50L);
stopWaitCursor(frame);
frame.repaint();
It works, but you can't see it ... Everytime your methode is adding a new scrollpane with a new reportpanel with a new JRViewer and so on. But you did not clear the old ones. Remove the older components from the mainpanel before.
reportPanel.removeall();
done the works. Now it's working properly. Thanks All for providing the support
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.