我在TextField上选择正确的操作时遇到问题。在Java类:
@FXML
private TextField projectNameInput;
@FXML
private void clearProjectName(MouseEvent event) {
// some if - else statements
projectNameInput.clear();
}
在FXML上看起来像这样:
<TextField fx:id="projectNameInput" onMouseClicked="#clearProjectName" GridPane.columnIndex="1">
我尝试了大多数选项,在Java中我尝试过(如arg)Event,MouseEvent,ActionEvent,结合FXML onAction等,但没有运气。当我在TextField上单击鼠标按钮时,我应该选择哪种操作,它会被自动清除?
答案 0 :(得分:3)
TextField1.addEventFilter(KeyEvent.KEY_TYPED , numeric_Validation(5));
AutoControl.setOnMousePressed(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
TextField1.clear();
}