I am writing a javaFx application that uses some editable ComboBox
controls. I want that when such a ComboBox
gains focus, then the text that is there in the ComboBox
gets highlighted. So I have this code below:
@FXML
ComboBox box;
box.focusedProperty().addListener(new ChangeListener<Boolean>(){
@Override
public void changed(ObservableValue<?extends Boolean> observable, Boolean oldValue, Boolean newValue){
box.getEditor().selectAll();
}
});
I even tried the following code:
@FXML
ComboBox box;
box.getEditor().focusedProperty().addListener(new ChangeListener<Boolean>(){
@Override
public void changed(ObservableValue<?extends Boolean> observable, Boolean oldValue, Boolean newValue){
box.getEditor().selectAll();
}
});
But both are not working. It would be very helpful if somebody could help me out.