是否可以在 java 代码中为文本字段设置背景文本?

Is it possible to set background text for textfields within java code?

可以在 EditText 字段中设置为背景文本吗?

    TextField field = new TextField("(*.xml, *.java...)");
    field.setStyle("-fx-prompt-text-fill: transparent;");

在java? 我不知道它的词,但我想将文本作为模板左右放在 editText 的背景中,例如登录表单等,有什么想法吗?

在此站点上方的搜索字段中点赞。

你的问题不是很清楚,但我认为你只是要求提示文字?

TextField field = new TextField();
field.setPromptText("(*.xml, *.java...)");

来自documentation

TextField supports the notion of showing prompt text to the user when there is no text already in the TextField (either via the user, or set programmatically). This is a useful way of informing the user as to what is expected in the text field, without having to resort to tooltips or on-screen labels.