Search code examples
javajavafx-2dynamic-reports

Main stage is getting closed whenever the report stage is getting closed


In my javafx application i am using DynamicReports which is free and open source Java reporting tool. In my code from a buttons event i am calling on a method to show the report:

report1.setOnAction(event -> {

                    getSupplierListReport();

                }

        );

And this is the method:

public void getSupplierListReport()
    {

        report = DynamicReports.report();


        try {
            //show the report


            report
                    .columns(
                            Columns.reportRowNumberColumn("No"),
                            Columns.column("First Name", "f_name", DataTypes.stringType()),
                            Columns.column("Last Name", "l_name", DataTypes.stringType()),
                            Columns.column("Email", "email", DataTypes.stringType())

                    )
                    .title(//title of the report
                            Components.text("Supplier List Report")
                                    .setHorizontalAlignment(HorizontalAlignment.CENTER).setStyle(boldCenteredStyle))
                    .pageFooter(Components.pageXofY().setStyle(boldCenteredStyle))//show page number on the page footer
                    .highlightDetailEvenRows()
                    .setColumnTitleStyle(columnTitleStyle)
                    .setDataSource("SELECT f_name, l_name, email FROM suppliers", connection)
                    .show();
            //export the report to a pdf file
            report.toPdf(new FileOutputStream("d:/report.pdf"));

        } catch (DRException e) {
            e.printStackTrace();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }


    }

The report is generating properly and there is no error. The think is when i am closing the main window the report window is not getting cold which is ok but whenever i am closing the report window its closing the whole application!!! may be somehow the dynamic reporting tools closing function is triggering to close the whole application. how to overcome the problem??


Solution

  • it seems like if i pass the parameter false in show method it won't close the application.

    .show(false);