标题翻译
How to add an action event to JavaFX textfield for focus?
问题
Controller:
@FXML protected void deleteInitialText(ActionEvent event){
passwordShown.focusedProperty().addListener((ov, oldV, newV) -> {
if(newV){
passwordShown.setText("");
}
});
}
FXML:
<TextField fx:id="passwordShown"
text="Password"
GridPane.columnIndex="1"
GridPane.rowIndex="2"
onAction="#deleteInitialText"/>
然而,这并没有产生任何结果。
英文翻译
I have a textfield for Password that has the text "Password" written in it. I want to make it so that whenever the textfield is clicked or gets focused that the text "Username" is deleted. This is the code that I have tried so far:
Controller:
@FXML protected void deleteInitialText(ActionEvent event){
passwordShown.focusedProperty().addListener((ov, oldV, newV) -> {
if(newV){
passwordShown.setText("");
}
});
}
FXML:
<TextField fx:id = "passwordShown"
text = "Password"
GridPane.columnIndex="1"
GridPane.rowIndex="2"
onAction="#deleteInitialText"/>
However, this does not produce any results.
专注分享java语言的经验与见解,让所有开发者获益!
评论