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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:05:39+00:00 2026-05-22T01:05:39+00:00

I have a problem with my application where the user will open more than

  • 0

I have a problem with my application where the user will open more than one window at a time. And i have added dispose() method to call on closing the window. Now i should keep at-least one window open all the time so that the application does not hides without closed fully. If you don’t understand read the following scenario:

I have window A and window B opened at the same time. Now i can close either window A or Window B but not both. In other words window B should be allowed to close only if window A is opened and vice versa. How do i do this in swing ??

  • 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-22T01:05:40+00:00Added an answer on May 22, 2026 at 1:05 am

    A simple kind-of windowManger is not really tricky, all you need is

    • WindowListener which keeps tracks of the Windows it’s listening to
    • a defined place to create the windows and register the the listener
    • make the windows do-nothing-on-close and make the listener responsible for the decision of whether to close or not (will do so for all except the last)

    Some snippet:

        // the listener (aka: WindowManager)
        WindowListener l = new WindowAdapter() {
            List<Window> windows = new ArrayList<Window>();
    
            @Override
            public void windowOpened(WindowEvent e) {
                windows.add(e.getWindow());
            }
    
            @Override
            public void windowClosing(WindowEvent e) {
                if (windows.size() > 1) {
                    windows.remove(e.getWindow());
                    e.getWindow().dispose();
                }
            }
        };
        // create the first frame
        JFrame frame = createFrame(l);
        frame.setVisible(true);
    
    
    // a method to create a new window, config and add the listener
        int counter = 0;
        private JFrame createFrame(final WindowListener l) {
            Action action = new AbstractAction("open new frame: " + counter) {
    
                @Override
                public void actionPerformed(ActionEvent e) {
                    JFrame frame = createFrame(l);
                    frame.setVisible(true);
    
                }
            };
            JFrame frame = new JFrame("someFrame " + counter++);
            frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
            frame.add(new JButton(action));
            frame.addWindowListener(l);
            frame.pack();
            frame.setLocation(counter * 20, counter * 10);
            return frame;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The users of my web application may have more than one browser window open
I have an 'access denied' problem on an ASP.NET web application, where the user
I have one sharepoint custom page application which is rendering from a user control.
In one ASP.NET application, we provide a link to open another application. If user
I have a windows form application. On the main form a user will enter
Here's the situation: I have a web-based ticket application, multiple users. One problem that
I have problem with my application. I have table report, there are 2 column
I have a problem with an application which uses the same stored procedure over
I have a problem linking an application for an embedded target. I'm developing on
I have problem concerning python packages and testing. I'm writing an application using wx

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.