How to close all child frames from parent frame?

408 Views Asked by At

I am now working with an application. In that there are lots of child JFrame objects there. Each time the button to show child frame is clicked a new instance of child frame is created and hence multiple copies of same child frame is created.

How can I prevent multiple copies of child node?

2

There are 2 best solutions below

0
On BEST ANSWER

You need to track whether child frame has already opened with button click. If it is, then dont create new form. If not create new child form and display it.

Or if your bussiness logic permits then, go for model dialogs. But better you ask your manager.

And as manoj pointed out, you can use boolean data types to flag displaying new form.

3
On

You can have boolean flag to store jframe state. Based on this flag u can prevent of creating multiple instance of JFrame.