35

How to set placeholder for TextField in JavaFX? How can I do this w/o JavaScript?

Tony
  • 3,605
  • 14
  • 52
  • 84
  • Related: [Clear prompt text in JavaFX TextField only when user starts typing](http://stackoverflow.com/questions/25125563/clear-prompt-text-in-javafx-textfield-only-when-user-starts-typing). – jewelsea Dec 13 '16 at 19:03

2 Answers2

62

Use the promptText property (see ref).

Nikos Paraskevopoulos
  • 39,514
  • 12
  • 85
  • 90
15

In JavaFX, you can set like the following:

TextField searchInput = new TextField();
searchInput.setId("textField");
searchInput.setPromptText("Search");
Jun Wei
  • 151
  • 1
  • 3