JDK-8101421 : Hiding a Stage cannot be cancelled in the onHiding's handle method
  • Type: Enhancement
  • Component: javafx
  • Sub-Component: application-lifecycle
  • Affected Version: fx2.0
  • Priority: P4
  • Status: Resolved
  • Resolution: Won't Fix
  • Submitted: 2011-06-30
  • Updated: 2015-06-16
  • Resolved: 2011-07-01
Related Reports
Relates :  
Description
After setting an EventHandler to a Stage via setOnHiding(...) the Stage is unconditionally hidden when the handler's handle(...) method returns.  IMO the primary purpose of differentiating between onHiding and onHidden is to permit canceling the hiding in the former.

Perhaps this could be implemented by not hiding the Stage if the WindowEvent is consume()d in the onHiding handler, or maybe by providing a defaultCloseOperation as in Swing's top level windows.

The first suggested approach could facilitate conditionally consume()ing a WindowEvent.WINDOW_HIDING in an EventFilter to prevent the window from being closed.

Discussion here: http://forums.oracle.com/forums/thread.jspa?threadID=2245058

db
Comments
Temporary workaround to prevent the FX application from closing is to open a dummy stage before hiding/closing the primary stage and hide/close the dummy stage after the the primary stage is shown... Stage dummyPopup = new Stage(); dummyPopup.initModality(Modality.NONE); // set as utility so no iconification occurs dummyPopup.initStyle(StageStyle.UTILITY); // set opacity so the window cannot be seen dummyPopup.setOpacity(0d); // not necessary, but this will move the dummy stage off the screen final Screen screen = Screen.getPrimary(); final Rectangle2D bounds = screen.getVisualBounds(); dummyPopup.setX(bounds.getMaxX()); dummyPopup.setY(bounds.getMaxY()); // create/add a transparent scene final Group root = new Group(); dummyPopup.setScene(new Scene(root, 1d, 1d, Color.TRANSPARENT)); // show the dummy stage dummyPopup.show();
29-12-2011

That does seem to beg the question: what's the difference between onHiding and onHidden? and why are they both needed? If as you imply, onHiding is always always always going to lead to onHidden, one handler should suffice for both. db
14-07-2011

The hiding / hidden window events are symmetric with showing / shown. The onHiding event handler is executed even when the Window is closed programmatically. In that case the developer probably doesn't want any dialog to be displayed and would need to use flags to handle that use case. We plan to add an additional close request window event and handler for it. How this new event can be used is described in RT-14297.
01-07-2011