I want to add some hint text in a textfield, like "name" or "surname". I create the textfield like this TextField userTextField = new TextField();
, but I cannot find how to do that. Here, I just found this Clear prompt text in JavaFX TextField only when user starts typing but I cannot believe this is the only way to do it. Or I am wrong?
I do it like this:
userTextField.setPromptText("name"); //to set the hint text
userTextField.getParent().requestFocus(); //to not setting the focus on that node so that the hint will display immediately