JavaFX Text Change Event


I designed a form in FXML document.I can handle keypress vs. events. But I need text change event.I'm using Netbeans 7.3 . There's three files in the projects: SampleControler, Sample.FXML and I found a code but I have not solved where to use it.

input.textProperty().addListener(new ChangeListener<String>() {
        public void changed(ObservableValue ov, String t, String t1) {                

My TextArea code is:

<TextArea layoutX="10" layoutY="50" maxHeight="125" minHeight="125" maxWidth="570" minWidth="570" editable="true" fx:id="input" prefWidth="570" prefHeight="125" />

What should I do?

6/22/2013 6:51:00 PM

Accepted Answer

In your controller associeted to your fxml, get your TextArea, and you will can do :

yourTextArea.textproperty().addListener ...

public class Example implements Initializable {

    private TextArea textArea;

    public void initialize(URL url, ResourceBundle resourceBundle) {
        textArea.textProperty().addListener(new ChangeListener<String>() {
            public void changed(ObservableValue<? extends String> observableValue, String s, String s2) {


The varibale name on the controller need to have the same name like the fx:id in the fxml

6/22/2013 8:07:52 PM

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