Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8400689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:37:23+00:00 2026-06-09T21:37:23+00:00

I am creating a java desktop application. In the application I generate report using

  • 0

I am creating a java desktop application. In the application I generate report using dynamic report and based on some parameter the report will generate. The user generates the first report and it is then displayed in a jasper viewer. The user minimizes the jasper viewer and generates next report. It is then viewed in a new jasper viewer.

So each time the user generates a report a new jasper viewer is created. How do I reuse or ensure only one JasperViewer exists at a time?

JasperPrint print=report.toJasperPrint();
JasperViewer.viewReport(print, false);

After that I created object for jasperviewer.

JasperViewer jv;
 JasperPrint print;
public void action()
{
  button.addActionListener(new ActionListener()
                {
                       @Override
                       public void actionPerformed(ActionEvent e) {
                          try
                          {
                             report.addColumn(...);
                               ...
                               ...
                              print=report.toJasperPrint();
                           jv=new JasperViewer(print,false);
                           jv.setVisible(true);
                          }
                        });
                 }
   }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T21:37:24+00:00Added an answer on June 9, 2026 at 9:37 pm

    Just to start off, you sample code does not compile. Once formatted correctly, you see that the closing parenthesis and semicolon happen to soon. It should look like:

    JasperViewer jv;
    JasperPrint print;
    public void action() {
      button.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
          try {
            report.addColumn(...);
            ...
            ...
            print=report.toJasperPrint();
            jv=new JasperViewer(print,false);
            jv.setVisible(true);
          }
        }
      });
    }
    

    Now to the question. JasperViewer extends JFrame and as such any tricks to close it programatically should also work for JasperViewer. Since you are storing a reference to the JasperViewer, you could check if it is already initialized. If it is send a window event to it to close it.

    if (jv != null && jv.isVisible()) {
        WindowEvent wev = new WindowEvent(jv, WindowEvent.WINDOW_CLOSING);
        Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(wev);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a Java desktop application where the user will enter his name
I am creating a Java Swing based desktop application in Netbeans. The application consists
I am creating a java desktop application. I am using mysql database as back
Possible Duplicate: Creating online help in Java Swing application - using pdf user docs
I'm creating a Java desktop application and was wondering how I should deal with
I'm creating a java desktop application that draws a map in a JFrame designing
When creating a new project in netbeans, if i select JAVA Desktop application, it
I am creating a Java application that will take in .tar files and retrieve
I'm creating a Java application where the user can search through a list of
Developing a desktop application based on Java + Swing I faced the problem of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.