Saturnian
Saturnian

Reputation: 1948

How to make JFrame exist independently without parent?

I am making a small application. From one JFrame, I am calling another JFrame. Now, I want this child JFrame to exist independently even after I've closed the parent JFrame. Is there any way I can do this? Or is this just NOT possible? Please help me. Let me know if you need me to post the code.

Thanks.

Upvotes: 2

Views: 969

Answers (2)

Guillaume Polet
Guillaume Polet

Reputation: 47608

On each JFrame, set the default close operation with #setDefaultCloseOperation to the following:

  • DISPOSE_ON_CLOSE

When you press the close-button of the frame, it will only close it and the other will continue its life until it is closed.

Note: I would recommend to avoid multiple Frames and rather try to use Tabs, it provides a better user experience.

Upvotes: 5

Rob Wagner
Rob Wagner

Reputation: 4421

Yeah it is definitely possible, just make sure the original frame isn't set to exit the application on close.

The second frame exists independently from the first, and you don't necessarily have to link the two if you don't want to.

Upvotes: 4

Related Questions