Reputation: 1813
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. In it setPromptText() function is working, but not showing the specified text content. This is because when the program is run, the textfield is the first control in it and when the window opens the textfield will be selected and so it does not shows the prompt text. How can I make the prompt text visible when the window opens ?
Upvotes: 5
Views: 4751
Reputation: 1
I had the same problem but after adding setFocusTraversable(false);
it works
Upvotes: -1
Reputation: 51525
Further digging revealed that it's a feature, not a bug - there are arguments for both:
To serve both sides, the behaviour is configurable via css, f.i.
name.setStyle("-fx-prompt-text-fill: derive(-fx-control-inner-background,-30%); }");
Upvotes: 8
Reputation: 3126
set FocusTraversable()
method to false
try this...
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;
}
Upvotes: 4