New properties: focusOwner and focusOwnerWithin

Michael Strauß michaelstrau2 at gmail.com
Sat Oct 7 21:00:57 UTC 2023


JavaFX has two closely related focus concepts: `Node.focused`, which
can apply to any number of nodes in a scene graph, and
`Scene.focusOwner`, which is the single node in a scene graph that
accepts user input.

JavaFX 19 added `Node.focusWithin`, which is a flag set on any node
that contains a `focused` node. However, there is no flag on `Node`
for the single focus owner, and also no flag that is set if a node
contains the single focus owner.

Tickets like [0] show that there might be a need for these additional
flags. One could argue that it might not be the best idea to set the
`focused` flag on a node that is not the focus owner (TableView does
this quite a lot), but I think that ship has sailed.

I've prepared a draft PR [1] that shows the proposed API of this
enhancement. The functionality can in theory be implemented by
applications, since the `Scene.focusOwner` property is already
available, but this is far from easy (especially when CSS is
involved).

I'm interested in your thoughts on whether this is an API that we want
to have in JavaFX.

[0] https://bugs.openjdk.org/browse/JDK-8317426
[1] https://github.com/openjdk/jfx/pull/1255


More information about the openjfx-dev mailing list