closing  child window from a frame

Posted on 2001-08-06
Medium Priority
Last Modified: 2012-05-04


I have a frame.In this frame I have a pop up menu
when the user selects "create" option from the pop up menu
I display another frame to create something

The problem is when I close the main frame I want to
dispose this second  frame

How do I do this
I tried doing this

f.addWindowListener(new WindowAdapter ()
         Window [] childWindows = null;
         public void windowClosing(WindowEvent event)

           System.out.println("in window closing event");

           childWindows = f.getOwnedWindows();
           System.out.println("childWindows" + childWindows.length );

           for(int i=0;i<childWindows.length;i++)
          System.out.println("destroy child window");
          String name = childWindows[i].getName();
          System.out.println("name" + name);



This does not work.
How do I do this.

Question by:sanjay_thakur
1 Comment

Accepted Solution

dviji earned 60 total points
ID: 6357450
Two ways,

1. In your parent window class keep track of your child windws, in your child window if you close the child window remove its refrence from parent and at the same time if you want to close the parent in the windowClosed() method (You should implement WindowListener)disposee all of its child.

2. In the Frame class use getFrames() class and dispose all the Frames in the parent's windowClosed() method (You should implement WindowListener).


Instead of creating child frames if you create Dialog and associate that dialog to your Parent frame. So if you close the child dialogs the Jvm close all of its childs().


Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses

607 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question