Search code examples
javacursortextfield

How to check in which textfield cursor is present in java?


How will we find that the cursor is now in that text field? I have two text fields in Java. I want to write text in a text field but before writing text I want to check which text field is selected. How can I check it?


Solution

  • You can use isFocusOwner():

    if(textField.isFocusOwner()) {
        // the cursor is in the TextField
    }