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!");
}
});
JavaFX: why can't be compile no matter what kind of `changeListener` I passed to `textArea.getKeyPressedProperty().addListener`
-
19-07-2023 - |
Domanda
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)
Soluzione 2
Altri suggerimenti
Are you sure you want add a listener to onKeyReleasedProperty()
property?
I guess you are seeking for
editor.addEventHandler(KeyEvent.KEY_RELEASED, new EventHandler<KeyEvent>() {
@Override
public void handle(KeyEvent event) {
}
});
Or in short as
editor.setOnKeyReleased(new EventHandler<KeyEvent>() {
@Override
public void handle(KeyEvent event) {
}
});
Otherwise assylias's answer is correct.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow