Solved

closing  child window from a frame

Posted on 2001-08-06
1
293 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

816 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now