我想在文本字段中添加一些提示文本,例如“姓名”或“姓氏”。我创建这样的文本字段 TextField userTextField = new TextField();
,但我找不到如何做到这一点。在这里,我刚刚找到了这个 Clear prompt text in JavaFX TextField only when user starts typing但我无法相信这是唯一的方法。还是我错了?
最佳答案
我这样做:
userTextField.setPromptText("name"); //to set the hint text
userTextField.getParent().requestFocus(); //to not setting the focus on that node so that the hint will display immediately
关于text - 如何在 JavaFX 的文本字段中添加提示文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34069030/