me.at.coding
me.at.coding

Reputation: 17654

Programmatically unfocus a TextField?

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!

Upvotes: 4

Views: 13289

Answers (2)

me.at.coding
me.at.coding

Reputation: 17654

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

Upvotes: 9

aclowkay
aclowkay

Reputation: 3877

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)

Upvotes: 0

Related Questions