3 Replies Latest reply: Feb 4, 2013 9:58 AM by ArtemAnaniev RSS

    onAlert for WebView inside JFXPanel

    905644
      I am trying to implement "alert" functionality in a webview that is inside a JFXPanel. Alerts need to be blocking, therefore I need to be able to block inside the onAlert event handler while I display the alert dialog to the user, then proceed after the user clicks OK.

      I am getting either deadlocks or crashes - but haven't found a successful strategy.

      Creating a modal dialog using a Java FX Stage (showAndWait()) causes a crash as soon as the dialog is closed. This is apparently because the top level window is an AWT/Swing window and not a JavaFX window, so it pukes.

      Attempting to create a modal dialog with Swing just deadlocks the system because (I presume) I have to wait inside the event handler for the swing thread to complete, but Swing needs to interact with the JavaFX thread in the mean time, which causes the deadlock.


      Any ideas how I can create a blocking alert box for a WebView inside a JFXPanel?

      -Steve
        • 1. Re: onAlert for WebView inside JFXPanel
          ArtemAnaniev
          Could you provide a crash log (hs_err_*.log), when it crashes with JavaFX stage, please?

          As for using Swing to implement onAlert() and similar callbacks, it should be possible. You can't just call SwingUtilities.invokeAndWait() as it indeed would lock FX thread. Instead, you need to run a nested FX event loop. Wait... it's not in JavaFX public API, unfortunately :(

          Have you tried Stage.showAndWait()? Is it the method that causes the crash?
          • 2. Re: onAlert for WebView inside JFXPanel
            905644
            Thanks for the reply.
            ArtemAnaniev wrote:
            Could you provide a crash log (hs_err_*.log), when it crashes with JavaFX stage, please?
            Unfortunately I don't have the error logs anymore.... wasn't able to get it working and just put it on hold. I just tried to set up a small example to reproduce, but now it seems to be working (in my simple example) with showAndWait(). The crash was happening in a more complex example that I don't have handy right now, so it is likely that there were other factors in the deadlocking.

            >
            As for using Swing to implement onAlert() and similar callbacks, it should be possible. You can't just call SwingUtilities.invokeAndWait() as it indeed would lock FX thread. Instead, you need to run a nested FX event loop. Wait... it's not in JavaFX public API, unfortunately :(
            Ahh.. that will be a very nice feature... I was looking all over for something like it.

            >
            Have you tried Stage.showAndWait()? Is it the method that causes the crash?
            Yes. That is the method that was crashing. The window would open, but it would crash as soon as I closed it. As I mentioned above, I can't seem to reproduce it right now with my simple example.. Will post here when I am able to reproduce.

            -Steve
            • 3. Re: onAlert for WebView inside JFXPanel
              ArtemAnaniev
              902641 wrote:
              Have you tried Stage.showAndWait()? Is it the method that causes the crash?
              Yes. That is the method that was crashing. The window would open, but it would crash as soon as I closed it. As I mentioned above, I can't seem to reproduce it right now with my simple example.. Will post here when I am able to reproduce.
              I tried to reproduce the crash too, but failed, at least on Windows. I tried both JFXPanel and Application modes, and it worked as expected... Please, provide a test, if you find a way to reproduce the crash.

              Thanks,

              Artem