Search code examples
javajavafxtextarealistener

JavaFX TextArea onSelectionChange method


Can I somehow implement a onSelectionChange method for my JavaFX Textarea? I want some code to fire on the selection change event but looks like, it doesn't have such a method. Is it possible to implement it with listeners?


Solution

  • Just add a listener to the text area's selected text:

    textArea.selectedTextProperty().addListener((obs, oldSelection, newSelection) -> {
        // ...
    });