Hi, how can I focus a textfield once it’s created? I’ve tried:
{:fx/type fx/ext-on-instance-lifecycle
:on-created #(.requestFocus %)
:desc {:fx/type :text-field}
Almost :) I had this problem as well. requestFocus does nothing then node is not on a scene, and it will be added to scene later
@jlmr I have this thing:
(defn focus-when-on-scene! [^Node node]
(if (some? (.getScene node))
(.requestFocus node)
(.addListener (.sceneProperty node)
(reify ChangeListener
(changed [this _ _ new-scene]
(when (some? new-scene)
(.removeListener (.sceneProperty node) this)
(fx/run-later
(.requestFocus node))))))))
(defn ext-focused-by-default [{:keys [desc]}]
{:fx/type fx/ext-on-instance-lifecycle
:on-created focus-when-on-scene!
:desc desc})
Don't remember why it's in run-later
, might be unnecessary
Works great, also without run-later
thanks again for all your help!
You are welcome 😊