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

Public API for Toolkit.canStartNestedEventLoop()

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • jfx21
    • javafx
    • None
    • source
    • minimal
    • Hide
      This adds the last missing nested event loop method to the Platform class.
      Since Platform is final, there is no risk in adding this method.
      Show
      This adds the last missing nested event loop method to the Platform class. Since Platform is final, there is no risk in adding this method.
    • Java API
    • JDK

      Summary

      Add the method canStartNestedEventLoop to the Platform class to provide a method for checking whether it is safe to start a nested event loop or not.

      Problem

      JavaFX provides methods to enter or exit a nested event loop via the Platform class. It is also possible to check if a nested event loop is running. JavaFX also uses these methods in the dialog or print API.

      Before a nested event loop can be started, a check is performed: Toolkit.getToolkit().canStartNestedEventLoop. If this check returns false, an exception is thrown. Since Toolkit is private sun API, one should not use this method and therefore is not able to check this condition before attempting to enter a nested event loop (either directly or indirectly).

      Solution

      Add the method canStartNestedEventLoop to the Platform class, so that developers are able to check if it is safe to start a nested event loop or not without using private API. This is also the last missing method that deals with nested event loops and is not included in the Platform class.

      Specification

      /**
       * Indicates whether a nested event loop can be started from the current thread in the current state.
       * A nested event loop can be started from an event handler or from a {@code Runnable} passed to
       * {@link #runLater(Runnable)}.
       * This method must be called on the JavaFX Application thread.
       *
       * @return {@code true} if a nested event loop can be started, and {@code false} otherwise.
       *
       * @throws IllegalStateException if this method is called on a thread other than the JavaFX Application Thread.
       *
       * @since 21
       */
      public static boolean canStartNestedEventLoop() {
          ...
      }

            mhanl Marius Hanl
            mhanl Marius Hanl
            Kevin Rushforth
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: