Friday 8 September 2017

JavaFx - TextField with placeholder

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
  TextField searchBox = new TextField();

  Text text = new Text("   Search");
  text.setStyle("-fx-fill:gray");
  text.visibleProperty().bind(searchBox.focusedProperty().not().and(searchBox.textProperty().isEmpty()));
  
  StackPane pane = new StackPane(text, searchBox);
  searchBox.setStyle("-fx-background-color:transparent;-fx-border-color:lightgray;-fx-border-radius:2%;");
  pane.setStyle("-fx-background-color:white;");
  pane.setAlignment(Pos.CENTER_LEFT);

No comments:

Post a Comment