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 6887317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:52:13+00:00 2026-05-27T05:52:13+00:00

I have a JFrame that opens a JFileChooser via an action event. When this

  • 0

I have a JFrame that opens a JFileChooser via an action event.

When this JFrame is disposed and the user opens up a new one and selects the JFileChooser they get one JFileChooser popup for each JFrame that has ever been open(and disposed).

Is this a common issue?

btnBrowse.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {


                int returnVal = fc.showOpenDialog(null);
                fc.showOpenDialog(null);
                if (returnVal == JFileChooser.APPROVE_OPTION) {
                    File file = fc.getSelectedFile();
                    System.out.println("Opening: " + file.getAbsolutePath());
                    filets = file.getAbsolutePath();
                    String shortName = file.getName();
                            if(shortName.length() > 9 ){
                                String roar = shortName.substring(0, 9);
                                String shortErName = roar+"...";
                                btnBrowse.setText(shortErName);                             
                            }
                            else {
                                btnBrowse.setText(shortName);
                            }
                } else {
                    System.out.println("Error Getting File!");
                }

            }
        });

And my browse button:

btnBrowse.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {


                JFileChooser fc = new JFileChooser();

                int returnVal = fc.showOpenDialog(null);
                fc.showOpenDialog(null);
                if (returnVal == JFileChooser.APPROVE_OPTION) {
                    File file = fc.getSelectedFile();
                    System.out.println("Opening: " + file.getAbsolutePath());
                    filets = file.getAbsolutePath();
                    String shortName = file.getName();
                            if(shortName.length() > 9 ){
                                String roar = shortName.substring(0, 9);
                                String shortErName = roar+"...";
                                btnBrowse.setText(shortErName);                             
                            }
                            else {
                                btnBrowse.setText(shortName);
                            }
                } else {
                    System.out.println("Error Getting File!");
                }
            }
        });
  • 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-05-27T05:52:14+00:00Added an answer on May 27, 2026 at 5:52 am

    I imagine what’s happening is that btnBrowse is getting one of these ActionListeners added each time you create a JFrame, but nothing is actually removing those listeners. If it’s the same JButton that survives the dispose of the JFrame — i.e, if the button itself is located elsewhere or if it’s just a member in some other class and you’re reusing it — then this is almost certainly the problem.

    You could override dispose() on the JFrame and call btnBrowse.removeActionListener() to get rid of the listener before calling super.dispose().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This one's a tough one - I have a JFrame that generates JTextFields. When
I have this class called PollFrame that extends JFrame in a file called PollFrame.java
I have a JFrame that contains a JTextPane. The purpose of this JTextPane is
I have a main JFrame that is interactive, i.e. user sets different options. After
I have this logical problem regarding on how to pass value from one JFrame
I have a JFrame that contains a display JPanel with JTextField and a control
Java Newbie here. I have a JFrame that I added to my netbeans project,
My current problem is that I have a JFrame with a 2x2 GridLayout. And
I have a program that creates a JFrame and makes it visible. Is there
I have an application that is works fine and the JFrame for it is

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.