Programmatically unfocus a TextField?

回眸只為那壹抹淺笑 提交于 2019-12-10 15:24:42

问题


On my view I only have one editable content: Text in a TextField. The problem is that as a user one never gets rid of the focus (because there is nothing else to focus on), once the TextField is focused. I want to remove the focus from the TextField when the user presses Enter. I know how to react to the Enter key being pressed, but I don't know how to unfocus a control/TextField programmatically?

Thanks for any hint!


回答1:


I admit I crossposted, but I got a reply there which I want to share here:

Call requestFocus() on the parent, e.g. in my case the HBox containing the TextField.

Full example on https://forums.oracle.com/forums/thread.jspa?messageID=10852574




回答2:


Yeah, I'm sorry, but I edited and added the correct link, if it for some reason isn't showing here: http://docs.oracle.com/javafx/2/api/javafx/scene/Node.html#setFocused(boolean)



来源:https://stackoverflow.com/questions/14883357/programmatically-unfocus-a-textfield

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!