1 Reply Latest reply on Sep 4, 2013 1:39 PM by RDarrylR

    Application Modal Stage(Window) possible in JFXPanel?


      I'm working on an app using JDK 1.7 (can't move to 8 yet) where the main view code is Swing. In one subapp I am creating a JavaFX Scene which is inside a JFXPanel. I have a JFrame which has a JPanel which has a JFXPanel which has the Scene.


      I am setting up "windows" to allow operations  which are launched off off of right click ContextMenu instances on the scene. I would like these "windows" to be modal over the JFXPanel or even the whole java app if easier.


      So far I have been creating instances of Popup and putting my nodes inside that. I then show the popup over the parent node. This works fine but the popup itself isn't really modal on the scene or app. It does stay open even if the user does other actions on the scene but it also stays open even if the user goes to another subapp which isn't fx and the JFXPanel goes out of focus.


      A couple of problems are that the main app can be moved around and the popup doesn't move with it. Also actions can still be performed on the scene while the Popup is shown. I can stop the actions by in the handlers checking if a popup is open and doing nothing if it is. Also I can hide the popup if the user switches away from the fx subapp by listening on focus events on the JFXPanel.


      Some of the actions launched from within the nodes inside the Popup require confirmation windows to the user. I have been able to get those to work and they do work modally like I expect. They are on top of the Popup window and the user can't do any actions underneath the confirmation window. The confirmation dialogs are implemented by creating a new Stage and setting it's parent to the Popup and setting the modality to Application or Window.


      Since the confirmation window behavior works as I wanted I am trying to make the content nodes of my Popups to behave the same way by putting them in a new Stage and setting the modality to Application or Window. For the parent of the new stage the only thing I can think of is to call getScene().getWindow() on the JFXPanel. This returns a Window instance (EmbeddedWindow I think) and  it seems to work ok with the initOwner() call on the new Stage.


      The new Stage shows up with my contents in it when launched from the right click ContextMenu on the stage. It does seem to be modal as I can't do any operations in the JFXPanel underneath. The problem is that if I do anything in the scene inside the JFXPanel then the 2nd stage goes to the back of focus. I set the 2nd stage to application modal. If I set the 2nd stage to window modal then the other nodes in the scene are not blocked and the 2nd stage isn't modal at all.


      I think I could accomplish what I want if I put another JFXPanel with the Popup contents in it inside of a JDialog every time but I would like to do this with JFX code only if possible.


      I guess the real question is if it's possible to have some kind of truly modal window that stays on top  of a scene inside a JFXPanel using JFX 2. Any ideas that don't involve moving to JFX 8 since that isn't possible for me?








      I see an exception now and maybe this is the real problem. I'm not sure if it was always happening or just started.


      Error: Unsupported type of owner com.sun.javafx.tk.quantum.EmbeddedStage@ce2dc4

      Exception in runnable

      java.lang.ClassCastException: com.sun.javafx.tk.quantum.EmbeddedStage cannot be cast to com.sun.javafx.tk.quantum.WindowStage

        at com.sun.javafx.tk.quantum.WindowStage.setVisible(WindowStage.java:422)

        at javafx.stage.Window$9.invalidated(Window.java:739)

        at javafx.beans.property.BooleanPropertyBase.markInvalid(BooleanPropertyBase.java:127)

        at javafx.beans.property.BooleanPropertyBase.set(BooleanPropertyBase.java:161)

        at javafx.stage.Window.setShowing(Window.java:779)

        at javafx.stage.Window.show(Window.java:794)

        at javafx.stage.Stage.show(Stage.java:229)

        at javafx.stage.Stage.showAndWait(Stage.java:395)



      Message was edited by: RDarrylR Added Exception


      Message was edited by: RDarrylR Changed title to be more clear

        • 1. Re: Application Modal Stage(Window) possible in JFXPanel?

          I changed the title as I think I understand the issue better now. I don't see the exception most of the time but the real question is if I can have an application wide (not just the JavaFx part but the whole outer app) modal stage shown inside a JFXPanel? If I open a Popup inside my JFXPanel on top of the JFXPanel scene then I can have a modal stage with the Popup as the parent. When trying to open a modal stage on top of the scene from the JFXPanel, the modal stage always gets pushed to the back of focus if I click on something outside the JFXPanel.