Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I know which node is focused in JavaFX?

Tags:

java

javafx

I have a lot of TextArea nodes in a Scene.

Is it possible for me to figure out which TextArea is selected (has the caret in it)?
I would like to be able to select the node and set it to a Node variable.

like image 443
Vasting Avatar asked Jun 12 '16 01:06

Vasting


1 Answers

Actually there is no need to set a focused node variable, because Scene already contains a focusOwnerProperty.

So you could use it e.g. like:

    if (scene.focusOwnerProperty().get() instanceof TextArea) {
        TextArea focusedTextArea = (TextArea) scene.focusOwnerProperty().get();
    }
like image 149
jns Avatar answered Oct 21 '22 20:10

jns