The setPromptText () function does not work initially with TextField

private VBox addVBox() {

    VBox vb1 = new VBox();
    vb1.setPadding(new Insets(40, 40, 20, 40));
    vb1.setSpacing(20);
    vb1.setStyle("-fx-background-color: #333333;");

    TextField txt1 = new TextField();
    txt1.setPromptText("Class Number");
    txt1.setPrefSize(70, 30);

    Button b1 = new Button("DELETE");
    b1.setFont(Font.font("Calibri", FontWeight.BOLD, 17));
    b1.setPrefSize(100, 30);
    b1.setStyle(" -fx-base: #ffffff;");
    b1.setTextFill(Color.BLACK);

    vb1.getChildren().addAll( txt1, b1);        
    return vb1;
}

This is my code. The setPromptText () function works in it, but the specified text content is not displayed. This is due to the fact that when the program starts, the text field is the first control in it, and when the window opens, the text field will be selected and therefore it does not display the invitation text. How can I make the tooltip text visible when opening a window?

+4
source share
2 answers

set method FocusTraversable() false

try it...

private VBox addVBox() {

VBox vb1 = new VBox();
vb1.setPadding(new Insets(40, 40, 20, 40));
vb1.setSpacing(20);
vb1.setStyle("-fx-background-color: #333333;");

TextField txt1 = new TextField();
txt1.setPromptText("Class Number");
txt1.setPrefSize(70, 30);
txt1.setFocusTraversable(false); // set focus traversable false.

Button b1 = new Button("DELETE");
b1.setFont(Font.font("Calibri", FontWeight.BOLD, 17));
b1.setPrefSize(100, 30);
b1.setStyle(" -fx-base: #ffffff;");
b1.setTextFill(Color.BLACK);

vb1.getChildren().addAll( txt1, b1);        
return vb1;
}
+3
source

Further digging showed that this is a function, not an error - there are arguments for both:

  • , , ,
  • ux , ,

, css, f.i.

name.setStyle("-fx-prompt-text-fill: derive(-fx-control-inner-background,-30%); }");
+4

Source: https://habr.com/ru/post/1536302/


All Articles