prompttext in textfield of javafx 2 hides on focus after some java 7 update

老子叫甜甜 提交于 2019-12-10 21:15:59

问题


i've been making simple javafx 2 gui application and found that prompttext in textfield of javafx 2 hides as soon as the textfield gets focus.

this wasn't this way some updates back. prior to this update, the textfield showed the prompttext until some text is typed into.

this isn't good and really need a workaround for this.


回答1:


I just solved this same issue by applying particular CSS rules to text inputs. Here's what I used (which should apply to all text-inputs)

.text-input, .text-input:focused { -fx-prompt-text-fill:darkgray; }



回答2:


Erem Boto's answer is just fine and should solve your problem!

Please see my answer here to see how to solve the problem if you use proper Java code (no FXML and CSS file).
(And also how to get the other behavior back).

In short, this is the solution:

In case your application interface is written using proper Java code.

Java Code:

textField.setStyle("-fx-prompt-text-fill: derive(-fx-control-inner-background, -30%);");

Where textField is your TextField component.


And in case your application interface is written using FXML and CSS, add the following to your CSS file.

JavaFX FXML (CSS):

.text-input, .text-input:focused {
    -fx-prompt-text-fill: derive(-fx-control-inner-background, -30%);
}


来源:https://stackoverflow.com/questions/17931794/prompttext-in-textfield-of-javafx-2-hides-on-focus-after-some-java-7-update

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!