requestFocus() is called *before* a node receives focus. Given the way it’s 
named it certainly looks like a way of initiating focus negotiation, not 
finalizing it. And it’s been possible to override this routine and re-direct 
focus since at least JavaFX 8. There’s one instance in Controls that uses it 
for exactly this purpose (the dreaded FakeFocusTextField).

With that said it’s a very weak framework for focus negotiation. For example it 
doesn’t allow ComboBox and Spinner to re-direct focus away from sub-nodes. I 
can think of a few message-based ways of negotiating focus that would cover a 
lot more ground. And for API compatibility I would probably initiate those 
negotiations from requestFocus(). It is the beginning of establishing focus, 
not the end. The end of focus negotiation (such as it is) occurs when the node 
becomes the scene’s focus owner. There’s no direct way for a node to determine 
when that happens beyond monitoring the scene’s focusOwner property.

Florian, why are you overriding requestFocus() to begin with?

Martin

> On Jul 29, 2026, at 5:14 PM, Kevin Rushforth <[email protected]> 
> wrote:
> 
> I said something similar in the JBS issue about this being previously 
> undocumented behavior. I agree with Michael on this issue.
> 
> -- Kevin
> 
> 
> On 7/29/2026 12:19 PM, Michael Strauß wrote:
>> requestFocus() was never specified to be called when focus changed,
>> which is also reflected in its name: it's not called onFocusChanged()
>> or something like it, it suggests a request only.
>> 
>> You point out that previously, an application could "decide what to do
>> when a node receives focus. For example, a node could pass the focus
>> on to another one."
>> 
>> I don't think that we should be supporting any attempt to subvert the
>> focus system, it's just not worth it. The Node.setFocused() situation
>> is bad enough as it is. Most legitimate use cases for hacks like that
>> can be solved by a focus delegation system, which seems to be due for
>> our annual discussion round.
>> 
>> So I'm in favor of doing nothing here, except maybe documenting that
>> you shouldn't override requestFocus().
> 

Reply via email to