I would like to hide the input caret of a TextField in JavaFX8. I already tried to set the text fill to white (my TextField has a white background), but then my user input a
I already found a workaround for this, and I want to share this with you of course. If anyone else wants to hide the caret until user input, you can use this:
I have created a change listener, which changes the text color on user input.
textfield.textProperty().addListener(new ChangeListener(){
@Override
public void changed(ObservableValue extends String> observable,
String oldValue, String newValue) {
if (!textfield.getText().trim().isEmpty()) {
textfield.setStyle("-fx-text-fill: black");
} else {
textfield.setStyle("-fx-text-fill: white");
}
}
});
Make sure the text fill is white on startup, I did this in the css file of my FXML:
#textfield {
-fx-text-fill: white;
}
Sorry for bothering you all with this question. However, this subject is not greatly discussed online, so I hope it could be useful for some of you.