RFR: 8343956: Focus delegation API [v3]

John Hendrikx jhendrikx at openjdk.org
Thu Jul 31 01:54:04 UTC 2025


On Thu, 31 Jul 2025 01:20:06 GMT, Michael Strauß <mstrauss at openjdk.org> wrote:

> _Mailing list message from [Andy Goryachev](mailto:andy.goryachev at oracle.com) on [openjfx-dev](mailto:openjfx-dev at mail.openjdk.org):_
> 
> I think I narrowed down my objection to this proposal. My main problem with it is that it tries to add properties to the wrong entity (Node).
> 
> In a typical application, the focus traversal requirements usually come in the context of a higher level aggregate such as a form, or a panel, or a window, and not the individual nodes. An example from Swing and AWT is the FocusTraversalPolicy class. This is no accident - the focus traversal might be dynamically dependent on other aspects of the UI state, for example the kind of information already present in a form.

The reason Swing has a FocusTraversalPolicy is because its layout system is decoupled from focus traversal. Layout managers in Swing determine the positions of components but do not expose any information about a good traversal order of those components. As a result, the container has no built-in understanding of how focus should move between components based on layout.

So Swing needed a FocusTraversalPolicy because layout managers (although flexible) do not provide any inherent information on focus traversal order. In contrast, JavaFX integrate layout and focus order more tightly through hierarchical scene graphs, node ordering, and orientation (for some controls).  In other words, there is more than enough ways to influence focus traversal order:

- Making logical groups which comes naturally with the various containers
- Adding nodes to containers in the desired focus order
- Leveraging disabled, visible, and focusTraversable properties for even more control

For instance, if a GridPane should traverse top-to-bottom rather than left-to-right, it’s simply a matter of adding the nodes in top-down order. JavaFX respects the order in which nodes are added, regardless of their visual grid positions.

So, I don't think grabbing this idea from Swing and adding it to FX can ever be the right solution as it was introduced there to solve a completely different problem (not using order of children + layout managers being decoupled and unable to confer focus traversal information).  If there are currently problems with FX's focus traversal order that can't easily be solved by using the existing tools (especially node order), that are common problems for users, then please share these, and let's see how these concerns can be addressed by enhancing what is already there instead of overriding it.  Perhaps a `Node.setViewOrder` type mechanism is needed, but for focus -- but I struggle to think why this couldn't be solved by simply moving the child in the correct position...

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

PR Comment: https://git.openjdk.org/jfx/pull/1632#issuecomment-3138313755


More information about the openjfx-dev mailing list