I need to track when an HTMLEditor element in JavaFX gets focus or loses it. I used a listener for textArea, but it doesn't work in this case.
htmlEditor.focusedProperty().addListener(((obs, oldValue, newValue) ->{
if (newValue) {
// focus received
}else{
//focus is lost
}
}));
I did face the same issue while adding a
ChangeListenerto the focused Property where the listener was not being invoked. However, there is another possible workaround for this. You can simply access yourScene's focus ownerNodeand add aChangeListenerto it to detect the old and new focusedNodewhich in your case is anHTMLEditorcontrol which is aNodeof typeWebView. The code would look something like this: