Reputation: 1825
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")).
Upvotes: 18
Views: 24427
Reputation: 6352
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
}
});
Upvotes: 55
Reputation: 1572
Using Lambda expressions
textArea.textProperty().addListener((obs,old,niu)->{
// TODO here
});
Upvotes: 8
Reputation: 666
As with all of JavaFX, just add a listener to the TextArea textProperty()
.
Upvotes: 20