JavaFX TextArea onChange event


Question

Good day developers :)

Does JavaFX component, TextArea, have support for some event like onTextChange or similar? Yes, I know for keyPressed, keyTyped ... but how to handle event if another "action" do changes on TextArea (eg. txArea.setText("some text")).

1
14
3/25/2012 6:59:00 PM

Accepted Answer

As with all of JavaFX, just add a listener to the TextArea textProperty().

17
7/26/2015 9:11:57 PM

This is the code:

textArea.textProperty().addListener(new ChangeListener<String>() {
    @Override
    public void changed(final ObservableValue<? extends String> observable, final String oldValue, final String newValue) {
        // this will run whenever text is changed
    }
});

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon