On Thu, 12 Mar 2026 22:27:39 GMT, Marius Hanl <[email protected]> wrote:
>> As also discussed back then in the mailing list, there are weird issues
>> around gaining focus when a `Control` is not focus traversable but got a
>> click event.
>>
>> - Some Controls do not call `requestFocus()` when they are not focus
>> traversable and receive a mouse click
>> - It is very inconsistent which Controls do it and which do not. Sometimes,
>> just a part of a `Control` will request focus, while another one will not
>> - Manually calling `requestFocus()` always works
>>
>> It seems like there is a misconception between beeing not focus traversable
>> and not requesting focus. The focus traversable property should only affect
>> keyboard navigation really. A mouse click should always request a focus.
>>
>> Check the Ticket for a reproducer with all `Control`s and a short list which
>> Controls do not behave (and which do).
>>
>> This PR removes the pattern that was wrongly used in some `Control`s.
>> From:
>>
>> if (getNode().isFocusTraversable()) {
>> getNode().requestFocus();
>> }
>>
>> To:
>>
>> getNode().requestFocus();
>
> Marius Hanl has updated the pull request incrementally with one additional
> commit since the last revision:
>
> revert change in Node
modules/javafx.graphics/src/main/java/javafx/scene/Node.java line 8586:
> 8584: */
> 8585: private void focusSetDirty(Scene s) {
> 8586: if (s != null && this == s.getFocusOwner()) {
Thinking about this twice, I will revert this change here.
The focus traversable is not checked in the focus dirty code:
https://github.com/openjdk/jfx/blob/11d65f19372dc643a985fbeffab094b76578406c/modules/javafx.graphics/src/main/java/javafx/scene/Scene.java#L2637-L2651
But the `Scene.this.focusInitial();` might change the initial focused node when
the focus traversable changed from `false` to `true`.
So the scenario could be:
1. Nothing is the focus owner
2. A `Node` is set to focus traversable `true` (from `false`)
3. Now this code runs and `focusInitial()` is called to traverse to the now
traversable `Node`
-------------
PR Review Comment: https://git.openjdk.org/jfx/pull/2106#discussion_r2927737341