Focus events in JavaFX

Jonathan Marchand jonathan.marchand68 at gmail.com
Mon May 20 08:17:43 UTC 2019


Hello,

When the main frame of my application gains focus, I would like to be able
to know where it came from. This is because I want to trigger certain
events when the focus comes from outside my application (as opposed to some
internal dialog or window being closed).
As far as I know, currently in JavaFX there is only the boolean property
focused, which does not help in my situation.

In Swing, there was a method FocusEvent.getOppositeComponent, which allowed
me to do just that: if the opposite component is null, then the window that
previously had focus was outside my JVM.

More generally, I think that knowing which Node/Control had focus when you
gain it (or gained it when you lose it) would be valuable to other
developpers.
I'd like to request such a feature to be added in JavaFX.

PS: I posted a question related to this on StackOverflow:
https://stackoverflow.com/questions/56172580/equivalent-of-focusevent-getoppositecomponent-in-javafx

Regards.


More information about the openjfx-discuss mailing list