Using setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) with multiple JFrame's

Hi!

I am running an application which uses multiple JFrame's running in separate threads. To close a JFrame I have set:
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

The problem now is, that closing one JFrame closes all JFrame's, and I only want to close the selected JFrame.

How do I solve that?

Regards,
Jesper
jespersahnerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

InteractiveMindCommented:
That causes the JVM instance to end when the frame is closed.

Generally, you'd just add a WindowListener to your JFrame, and then either destroy() it, or hide it using setVisible(false).
0
InteractiveMindCommented:
An example:

JFrame fr ;  // global
.
.
WindowListener l = new WindowAdapter()
{
    public void windowClosing( WindowEvent evt )
    {
        // close here
        fr.setVisible( false ) ;
        // or fr.destroy() ;    <-- probably the best one to use
    }
} ;
fr.addWindowListener( l ) ;
0
CEHJCommented:
Just use

JFrame.DISPOSE_ON_CLOSE
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

CEHJCommented:
i.e.

setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
0
InteractiveMindCommented:
Oh. That's easier :)
0
jespersahnerAuthor Commented:
->CEHJ: Thanks! Reading the manual often solves the problem, which I didn't in this case :-))
0
jespersahnerAuthor Commented:
-> InteractiveMind: Thanks for your input anyway :-)
0
CEHJCommented:
:-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

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.