RFR: JDK-8302355: Public API for Toolkit.canStartNestedEventLoop()

Kevin Rushforth kcr at openjdk.org
Wed Feb 15 16:09:35 UTC 2023


On Mon, 13 Feb 2023 19:31:56 GMT, Marius Hanl <mhanl at openjdk.org> wrote:

> This PR adds the last missing method for dealing with nested event loops.
> As also written in the ticket, there is currently no (public) way to find out whether it is safe to start an event loop now or not.
> Classes like `Dialog` check via `Toolkit.getToolkit().canStartNestedEventLoop()` (sun api), if it safe to start a nested event loop before doing so.

I left one API comment, which will also require a small change to the Toolkit method.

Also, please provide a test.

modules/javafx.graphics/src/main/java/javafx/application/Platform.java line 396:

> 394:     /**
> 395:      * Indicates whether a nested event loop can be started from the current thread in the current state.
> 396:      * Note that a nested event loop is not allowed outside an event handler.

You need to be explicit about whether or not this method must be called on the JavaFX thread. The two logical choices are:
1. Add a statement indicating that this method must be called on the JavaFX Application thread. The toolkit method would then call `checkFxUserThread()`, as do the other nested event loop methods.
2. Add a statement indicating that this method may be called on any thread (and that it will return false if not on the JavaFX application thread). The toolkit method would then first call `isFxUserThread()` and return  false if not.

I might lean towards option 2, but don't have a strong preference.

-------------

PR: https://git.openjdk.org/jfx/pull/1031


More information about the openjfx-dev mailing list