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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T11:20:47+00:00 2026-06-03T11:20:47+00:00

I have a class like this: public class A { public static void main()

  • 0

I have a class like this:

public class A {
    public static void main() {
        B f1 = new B();
        f1.setVisible(true);
    }

    class B extends JFrame {
        public B() {
            JButton btn = new JButton("click me");
            btn.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    C f2 = new C();
                    f2.setVisible(true);
                }
            });
            add(btn);
        }
    }

    class C extends JFrame {
        public C() {
            //whatever here
        }
    }
}

When I first run this java code,
a window X contains a button “click me”. After I click it, another new window Y is popped out.
But the problem is that when I close the new window Y, the old window X is closed together with Y automatically. (i.e. they are closed at the same time)

What I wanna do is that after I close Y, X keeps there and not to be closed. How to do it?

  • 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-03T11:20:48+00:00Added an answer on June 3, 2026 at 11:20 am

    You would change the argument of the setDefaultCloseOperation() method, which defines what happens when the close button is clicked. In this case, you would use DISPOSE_ON_CLOSE as the argument. The reason both frames are being disposed is presumably because you set the argument to EXIT_ON_CLOSE (if you didn’t set this explicitly, then it was done for you; it is the default close behavior for all frames) which terminates the entire process—this includes all open windows and frames. If you need further assistance, please ask. 🙂

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

Sidebar

Related Questions

Assume I have a class like this: public class Server { public static void
I have created my own Attached Property like this: public static class LabelExtension {
I have a program like this - import weka.core.stemmers.SnowballStemmer; public class TestProject{ public static
I have a class like this public class foo { private void getThread() {
I have a class called Paragens like this: public class Paragens { static int
I have a util class like this: public class Util { static public List<Person>
I have a class like this: public class Contest { List<ContestTeam> Teams { get;
I have a class like this: class MyClass{ public: MyClass(int Mode); private: std::map <
I have a class that looks like this: public class BasePadWI { public WorkItem
I have a class like this class GUI : public QWidget, public QThread When

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.