iReport Plugin Demo (Using the Report Wizard) (5 Minutes)


This presentation is part of the NetBeans Day World Tour and is used in the session New & Cool in NetBeans. This demo focuses on the iReport plugin capabilities using the report wizard.

Product Versions Supported

  • NetBeans 6.0.1, it does not yet work in 6.1 :-(

Points to Hit

You will be emphasizing the fact that NetBeans now has built in report building capabilities.

Demo Prep

  1. Download and extract JasperReports. Create a library called JasperReports containing dist/jasperreports-2.0.4.jar and all the jars in the lib directory (the next release of the plugin will handle set this up automatically)
  2. Install the iReport Plugin .
  3. Add an iReport data source by doing the following.
    1. Select the Tools > Report Datasources Menu item.
    2. Select the "New" button and choose "NetBeans Database JDBC Connection".
    3. Click "Next" and name the connection Sample DB. Set the Connection to
      jdbc:derby://localhost:1527/sample [AppOnAPP]


Be careful that the detail fields actually end up in the detail section. If they end up in the column header the Preview WILL NOT work. You can verify field locations by looking at the Outline window as it is possible for the visual designer to be out of synch with where the field actually resides. You can drag fields from section to section using the Outline window.


Create the Desktop Application

First create a desktop application to which we'll attach the report. This could be done ahead of time.

  1. Create a new Java Desktop Application project named CustomerManager. Select Database Application:
  2. Click Next and select sample as the Database Connection and CUSTOMER as the Database Table. Select NAME, ADDRESSLINE1, CITY, STATE and ZIP as the columns to include:
  3. Click Next and Create the Details Area as Textfields and click Finish.
  4. Run the application to show what we have thus far. SC: "You're may be surprised at how quickly we've created this Swing application, but that's not the point of this demo. Consider what you have seen thus far as a teaser for the upcoming Introduction to the Swing Application Framework and Beans Binding session later today. Our goal here is to create a report of our customer data."

Create the Report

  1. Open the New File dialog and select Report > Report
  2. Name the report customerReport.jrxml. Set the folder to src/customermanager
  3. Set the Connections / Data Sources to Sample DB (check the Demo Prep if you don't see this connection)
  4. Select Design query. Select the APP.CUSTOMER table and then the NAME, ADDRESS, ADDRESSLINE1, CITY, STATE and ZIP columns:
  5. Click OK to close the query designer and then Next.
  6. Select all the fields and click Next
  7. Set the Group 1 to CUSTOMER_STATE
  8. Set the Layout to Tabular Layout
  9. Click Next and then Finish to generate the report
  10. After the report opens in the designer, select Preview to see what we have
  11. Return to the designer and change the title to Customer Report

Add a Graph to the Report

This part of the demo will add a variable to count customers per state, and then a graph to display them

  1. In the Outline window, Right-click the Variables node to add a new variable. Set the following property values:
 - Name: customersPerState
- Variable Class: java.lang.Integer
- Calculation: Count
- Reset Type: Group
- Variable Expression: ""
(note, for me, the variables are not readable after being set)
  1. Select the summary node in the Outline window and set its Band height property to 250 (I don't know if it's possible to stretch it from 0 using the visual designer)
  2. Drag a Chart from the Palette into the report summary. Select Pie when the chart type dialog opens.
  3. Resize and center the chart to fit the summary section:
  4. Right-click the chart and select Chart Data
  5. Set the Increment type to Group.
  6. Click the Details tab
  7. Use the Expression Editor to set the Key expression to $F{CUSTOMER_STATE}:
  8. Use the Expression Editor to set the Value expression to the variable we created above, $V{customersPerState}
  9. Close the Chart details dialog and Preview the report - you'll find the chart on page 2.

Call the Report From the Application

  1. Add the JasperReports library to the project.
  2. Switch to the CustomerManagerView and drag a button onto the designer left of the "New" button:
  3. Double-click the new button to open the Set Action dialog.
  4. Set the following:
 - Action: - Create New Action...
 - Action's Method - runReport
 - Attributes -> Text: Run Report
  1. Click OK. Add the following code to the new "runReport" method.
        try {
            String reportName = "customermanager/customerReport.jasper";
            InputStream is = this.getClass().getClassLoader().getResourceAsStream(reportName);
            Connection conn = DriverManager.getConnection("jdbc:derby://localhost:1527/sample", "app", "app");
            JasperPrint jasperPrint = JasperFillManager.fillReport(is, new HashMap(), conn);
            JasperViewer jv = new JasperViewer(jasperPrint);
        } catch (Exception ex) {
  1. Fix the imports
  2. Run the application and press the "Run Report" button.

Demo Cleanup

  • Delete the CustomerManager Project



Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo