How to prevent parent window from closing while child window is opened/running. And if possible, parent window will not be disabled.
1 Answers
The "normal" UI theme to do that is to make the child window modal. Meaning: the UI only allows to deal with the child window, and thus prevents any other clicks or actions that would affect the parent window.
But:
And if possible, parent window will not be disabled.
If you really want that, then the child can't be modal. Then you have to do all these things manually. In other words: you have to implement WindowListeners, ActionListeners, ... on your parent window that intercept any attempts to close that window. And depending on "child window is up" prevent or allow that. See here for a first glance. But depending on what exactly your parent window is able to do, you are looking for a lot of other work, too!
And please note: as said, this means a lot of work and it is not what most people would expect.

- 137,827
- 25
- 176
- 248
-
Thank you for your answer :) Will check it out. – Newbie Coder May 20 '19 at 05:02
-
@NewbieCoder You are very welcome ... and it case the answer is sufficient, feel free to accept. Otherwise let me know if you need more infos. – GhostCat May 20 '19 at 05:36
-
1Note, in JavaFX, you only need `window.setOnCloseRequest(event -> { if (otherWindow.isShowing()) { event.consume(); } });` if you don't want use use a modal window. – Slaw May 20 '19 at 05:37
-
1@Slaw Maybe. Or there is a menu item to close the window, and another action here or there. Dont make promises that aren't easy to hold ... – GhostCat May 20 '19 at 05:38
-
1Well, you could always fire a `WindowEvent.WINDOW_CLOSE_REQUEST` from inside those menu items/other actions instead of calling `Window#hide()` ;) But I see your point. – Slaw May 20 '19 at 05:43