On Thu, 17 Jul 2025 05:18:28 GMT, Michael Strauß <[email protected]> wrote:

>> Implementation of [focus 
>> delegation](https://gist.github.com/mstr2/44d94f0bd5b5c030e26a47103063aa29).
>
> Michael Strauß has updated the pull request incrementally with one additional 
> commit since the last revision:
> 
>   Avoid variable reassignment

@maran23 These days I try to avoid using the term “focus”. In JavaFX that can 
mean many different things. A node might have “focus” if:

1) it’s the focus owner of a scene;

2) it’s the focus owner of a scene and the scene’s stage is the active window;

3) it matches the “focus” pseudo-class and displays a focus ring;

4) it’s the target of key events.

The Node focused property used to track definition 2. Now it’s a fuzzy 
combination of 2 and 3.

When you say you want to implement “commit on focus lost” does that include 
when the stage loses OS focus (definition 2)? That’s the behavior you would get 
using the Node focused property. If committing could cause an alert to pop up 
you might be creating a usability problem; when the user tries to check their 
e-mail the JavaFX app would keep popping an alert.

The Controls side of JavaFX is using a composition approach that the Graphics 
side of JavaFX wasn’t designed for. A ComboBox wants the focus owner to be the 
logical control (the ComboBox) and the key event target to be the internal 
TextField. The Scene doesn't currently make that distinction.

(It’s interesting to compare JavaFX with the Win UI toolkit which was designed 
for composition. Win UI makes a distinction between the logical control and the 
key event target and its Event object can track both elements.)

This PR separates the focus owner and the event target by introducing the 
delegate. The downside is that a delegate can in turn have a delegate which 
complicates things. It might make more sense for Scene to track the key event 
target as a property separate from the focus owner. Based on your comments it 
looks like the "focused" Node property should remain with the focus owner but 
the "focus" pseudo-class should follow the key event target.

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

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

Reply via email to