0

How to prevent closing the first frame while the second is still open frame is open in a Java GUI? Both the frames are related to each other.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • how to prevent closing the first frame while the second frame is still open in java GUI. both the frames are related to each-other. – Nikhil Channavar Jul 01 '21 at 11:24
  • 2
    Please [edit] your question to privide a [mre]. Without any code, you are not likely to get the help you want. Nonetheless, this should be considered: [The Use of Multiple JFrames: Good or Bad Practice?](https://stackoverflow.com/questions/9554636/the-use-of-multiple-jframes-good-or-bad-practice) Closing the "first frame" will most likely terminate your program, therefore also closing the "second frame". – maloomeister Jul 01 '21 at 11:30
  • Give this a read: [Preventing JFrame window from closing](https://www.codejava.net/java-se/swing/preventing-jframe-window-from-closing). Play with it a bit. – DevilsHnd - 退職した Jul 01 '21 at 11:52
  • 2
    Don't use muiltiple JFrames. An application should only have a single JFrame. If you need a second child window then use a `modal JDialog`. You will not be able to click on the JFrame until the dialog is closed. – camickr Jul 01 '21 at 14:08
  • @camickr Perhaps questioner would like a multi-frame program like Eclipse? Or for multiple reasons given in this answer to another question: https://stackoverflow.com/a/17961122 Myself, I have made an application that allows users to float JInternalFrames to become JFrames and vice versa. – Alan Jul 01 '21 at 14:54

0 Answers0