coding, programming, working-924920.jpg

Launch Jasper report on the same screen / monitor from javafx

I did not find on the web a solution how to load jasper reports on the same screen or monitor where you launch it. For instance you have multiple monitors and run a javafx application. When you launch the report it opens by default on primary screen. I had this issue for a quite sometime and I did not find a good and simple solution. Here is what I discovered myself.

—————————————————-

in = clazz.getResourceAsStream(“/reports/Asigurari.jrxml”);
con = MsSqlMain.getConnection();
JasperDesign jasperDesign = JRXmlLoader.load(in);
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
JasperPrint print = JasperFillManager.fillReport(jasperReport, null, con);
JasperViewer jp = new JasperViewer(print, false);
jp.setLocationByPlatform(true); // — here is the magic code 🙂
jp.setVisible(true);

—————————————————-

Leave a Reply

Your email address will not be published.