我如何知道JavaFX中关注哪个节点?

Vas*_*ing 9 java javafx

TextArea在场景中有很多节点.

我有可能弄清楚哪个TextArea被选中(插入了插入符号)?
我希望能够选择节点并将其设置为Node变量.

jns*_*jns 16

实际上没有必要设置一个聚焦节点变量,因为Scene已经包含了一个focusOwnerProperty.

所以你可以使用它,例如:

    if (scene.focusOwnerProperty().get() instanceof TextArea) {
        TextArea focusedTextArea = (TextArea) scene.focusOwnerProperty().get();
    }
Run Code Online (Sandbox Code Playgroud)