954,518 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Close JFrame

Hi all,

I've got a JFrame in a program, and when I click on a button, I get another JFrame created, and then select from a list.

This works fine. But my problem is that when I close the second JFrame the entire program exits (both the main JFrame and the second JFrame).

I've tried the following commands:

JFrame.EXIT_ON_CLOSE
JFrame.DO_NOTHING_ON_CLOSE
JFrame.DISPOSE_ON_CLOSE

But no luck with the above. At least I'm not getting them to work. They all close the entire program.

Any help much appreciated.

Thanks,
Jorge

jorgelex008
Newbie Poster
10 posts since Dec 2009
Reputation Points: 10
Solved Threads: 0
 

Haven't really dealt with this before, but have you tried:

JFrame.HIDE_ON_CLOSE

Not sure if the results will be different. Might have the main JFrame dispose of them both on exit

KirkPatrick
Junior Poster
162 posts since Apr 2009
Reputation Points: 38
Solved Threads: 8
 

Haven't really dealt with this before, but have you tried:

JFrame.HIDE_ON_CLOSE

Not sure if the results will be different. Might have the main JFrame dispose of them both on exit


tried that... no luck. not working for me.

jorgelex008
Newbie Poster
10 posts since Dec 2009
Reputation Points: 10
Solved Threads: 0
 

Well, your second JFrame probably has a call to setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE) somewhere in its setup code. You need to change that to use DISPOSE_ON_CLOSE or something else. Those are not commands. They are constants you use to specify the parameter value.

Ezzaral
Posting Genius
Moderator
15,986 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847
 

Hi all,

Thanks! I got the *constant* change to work.

Not sure what was happening before... somehow it was carrying the constant value from the first JFrame (???).

Thanks again from a Java newbie

jorgelex008
Newbie Poster
10 posts since Dec 2009
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: