I implemented a ComboBox which is editable and autocompletes itself similar to the one in this answer: https://stackoverflow.com/a/27384068/9611276
Now i want to add a listener which performs some action when the value in this Combobox changes. Something like this:
combobox.getValueProperty().addListener((obs, oldV, newV) -> {...});
The problem is, that i cannot access the combobox.getValueProperty() without getting a java.lang.ClassCastException. In the answer above it is mentioned to get the combobox value with the following function:
public static <T> TgetComboBoxValue(ComboBox<T> comboBox) {
if (comboBox.getSelectionModel().getSelectedIndex() < 0) {
return null;
} else {
return comboBox.getItems().get(comboBox.getSelectionModel().getSelectedIndex());
}
}
How do i create and access the property to add a listener?
Thanks, BR