Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

how do i close a jframe while retaining another one

  Asked By: Ludwig    Date: Apr 25    Category: Java    Views: 924
  

I have two JFrames: JFrame A and JFrame B. JFrame A
opens/ instantiates JFrameB. Now, the problem arises
when i want to close JFrame B only, by using the OK
button. I don't know what code to use to do that. I
tried putting the "System.exit(0)" inside the
actionPerformed() method but it closes both JFrames.

Share: 

 

2 Answers Found

 
Answer #1    Answered By: Cadencia Bernard     Answered On: Apr 25

System.exit(0) will close  the whole application. You need to maintain a
reference to JFrame B and call the dispose() method  on it when you want
to close it.

 
Answer #2    Answered By: Patty Freeman     Answered On: Apr 25

Use "setDefaultCloseOperation(int closeType)" in the constructors of
your frames

 
Didn't find what you were looking for? Find more on how do i close a jframe while retaining another one Or get search suggestion and latest updates.




Tagged: