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")).
The onchange element could be used on a textarea to launch a script after the user finishes filling in the field. The script could do something like enable the form submit button or enable a follow-up field that shouldn't be completed until the textarea has received input.
addListener. void addListener(ChangeListener<? super T> listener) Adds a ChangeListener which will be notified whenever the value of the ObservableValue changes. If the same listener is added more than once, then it will be notified more than once.
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
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
}
});
As with all of JavaFX, just add a listener to the TextArea textProperty()
.
Using Lambda expressions
textArea.textProperty().addListener((obs,old,niu)->{
// TODO here
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With