When using a CSS to style a Textfield the prompt text changes it's color as xpected, but when the user clicks on it the text doesn't dissapears neither the cursor appears, a work around is to make a class to do it:
@Override
public void initialize(URL url, ResourceBundle rb) {
busqueda.focusedProperty().addListener(new ChangeListener<Boolean>() {
@Override
public void changed(ObservableValue<? extends Boolean> ov, Boolean t, Boolean t1) {
if (!t1) {
busqueda.setStyle("-fx-prompt-text-fill: darkblue;"
+ " -fx-background-color: #999999, white;\n"
+ " -fx-background-insets: 1, 3;\n"
+ " -fx-background-radius: 0 0 9 0, 0 0 8 0, 0 0 8 0;\n"
+ " -fx-padding: 5px}");
} else {
busqueda.setStyle("-fx-prompt-text-fill: white;"
+ " -fx-background-color: #999999,#336699, white;\n"
+ " -fx-background-insets: 1, 2, 3;\n"
+ " -fx-background-radius: 0 0 9 0, 0 0 8 0, 0 0 8 0;\n"
+ " -fx-padding: 5px}");
}
}
});
}
@Override
public void initialize(URL url, ResourceBundle rb) {
busqueda.focusedProperty().addListener(new ChangeListener<Boolean>() {
@Override
public void changed(ObservableValue<? extends Boolean> ov, Boolean t, Boolean t1) {
if (!t1) {
busqueda.setStyle("-fx-prompt-text-fill: darkblue;"
+ " -fx-background-color: #999999, white;\n"
+ " -fx-background-insets: 1, 3;\n"
+ " -fx-background-radius: 0 0 9 0, 0 0 8 0, 0 0 8 0;\n"
+ " -fx-padding: 5px}");
} else {
busqueda.setStyle("-fx-prompt-text-fill: white;"
+ " -fx-background-color: #999999,#336699, white;\n"
+ " -fx-background-insets: 1, 2, 3;\n"
+ " -fx-background-radius: 0 0 9 0, 0 0 8 0, 0 0 8 0;\n"
+ " -fx-padding: 5px}");
}
}
});
}