On Fri, 1 Aug 2025 21:18:53 GMT, Andy Goryachev <andy.goryac...@oracle.com> 
wrote:

> There is more: I think the kind of issues we see stem from the sub-optimal 
> event dispatching mechanism in JavaFX, the weirdest part of which is creating 
> multiple event instances for the same event. The key events should be 
> targeting the keyboard focus owner, in case of the Spinner and similar 
> controls, the TextField inside of it. "Control" and "Skin" are abstractions 
> that have nothing to do with that, and the Spinner itself might conceptually 
> be a part of some other custom control.
> 
> To answer the last two points:
> 
> 1. the leaf TextField should be the focused Node, not its parent Control, or 
> its more complex custom control.

But that would be a bad experience for application developers. In most cases, 
application developers interact with a scene graph of controls. The skins are 
just an implementation detail that is mostly invisible, and easily changeable 
with a different theme.

Developers should be able to expect that when they `requestFocus()` on a 
control, the control will be focused. This is what JavaFX currently tries to do 
(but it fails to do it right). Your suggestion would be a major breaking 
change, it would mean that a skin arbitrarily gets to decide which node will 
_actually_ be focused.

This leaks an implementation detail into the user model with huge consequences: 
simply changing a skin becomes brittle and potentially impossible, as user code 
can no longer reason about controls independently from their skins. User code 
would no longer be able to know which node will be focused, or which node will 
be the target of events.

> 2. to avoid duplicate events, don't duplicate events.

Yes, this is the logical solution for your suggestion. But then observers will 
not be able to know that a key event is targeted at a spinner. Let's assume 
that a scene listener is installed that intercepts key events going to 
spinners. Using your suggestion, the listener would have to look whether the 
key event is targeted at a TextField (which is an implementation detail of a 
skin, and could change with another theme), and then figure out whether the 
parent of that TextField is a Spinner (which is another implementation detail).

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

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

Reply via email to