Solved

closing  child window from a frame

Posted on 2001-08-06
1
294 Views
Last Modified: 2012-05-04

hi,

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");
          childWindows[i].setVisible(false);
          String name = childWindows[i].getName();
          System.out.println("name" + name);
          childWindows[i].dispose();
           }

         }

    });

This does not work.
How do I do this.




 
0
Comment
Question by:sanjay_thakur
1 Comment
 
LVL 1

Accepted Solution

by:
dviji earned 20 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().

...dviji
0

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.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

809 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