Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8302355

Public API for Toolkit.canStartNestedEventLoop()

XMLWordPrintable

    • b09
    • generic
    • generic

      The JavaFX API lacks an useful method to find out whether it is safe to start a nested event loop or not.
      One example where this method is useful is the Dialog class. (Another one is printing)
      When calling dialog.showAndWait(), a check is performed:
      Toolkit.getToolkit().canStartNestedEventLoop(), which will throw an exception if false.
      The problem here is, that developers may wish to check this before calling showAndWait() but since the Toolkit is private sun api, it is not recommended to do so.

      Following the other nested event loop method, I propse to add Platform.canStartNestedEventLoop(), which is delegating to the Toolkit (just like the other methods).

      See also my mail in the mailing list from September 2022 https://mail.openjdk.org/pipermail/openjfx-dev/2022-September/035867.html

      Existing public API for nested event loops:
      - Platform.isNestedLoopRunning()
      - Platform.enterNestedEventLoop(..)
      - Platform.exitNestedEventLoop(..)

      Situations where canStartNestedEventLoop() is returning false:
      - When showing a dialog in a Timeline Keyframe
      - When showing a dialog when still in the layout phase
      -> When the pulse is running, it is not safe to show a dialog

      Currently possible workaround:
      - Toolkit.getToolkit().canStartNestedEventLoop()
      - try (dialog.showAndWait()) catch(IllegalStateException)

            mhanl Marius Hanl
            mhanl Marius Hanl
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: