Search code examples
javacompilationjavafxtype-systems

JavaFX: why can't be compile no matter what kind of `changeListener` I passed to `textArea.getKeyPressedProperty().addListener`


JavaFx code:

public class MyController implements Initializable {
    @FXML
    private TextArea editor;

    @Override
    public void initialize(URL url, ResourceBundle resourceBundle) {

        editor.onKeyReleasedProperty().addListener(new ChangeListener<KeyEvent>() {
            @Override
            public void changed(ObservableValue<? extends KeyEvent> o, KeyEvent oldVal, KeyEvent newVal) {
                System.out.println("changed!");
            }
        });
    }
}

This code can't be compiled on the lines of new ChangeListener..., and the error is:

Can't resolve method 'addListener
  (javafx.beans.value.ChangeListener<javafx.scene.input.KeyEvent>>)'

I have changed the code again and again, but I can't find a way to make it compile.

(I'm using Intellij-IDEA 13 + jdk 1.7)


Solution

  • editor.onKeyReleasedProperty().addListener(new ChangeListener<EventHandler<? super KeyEvent>> () {
      @Override
      public void changed(ObservableValue<? extends EventHandler<? super KeyEvent>> observable, EventHandler<? super KeyEvent> oldValue, EventHandler<? super KeyEvent> newValue) {
        System.out.println("changed!");
      }
    });