I have number of TextField
objects inside a pop up window called dialog (type : Stage
).
I am trying to define an action handler for them which aims to close the stage once the escape button is clicked on the key board.
Here is my function for the stage closer :
public void escapeKeyPressed(KeyCode keyCode , Stage dialog){
if (keyCode == KeyCode.ESCAPE ){
dialog.close();
System.out.println("escape got called");
}
}
and the following is where I call it :
textUsername.setOnAction((event) -> {escapeKeyPressed(KeyCode.ESCAPE ,dialog );});
textAddress.setOnAction((event) -> {escapeKeyPressed(KeyCode.ESCAPE ,dialog );});
textwp.setOnAction((event) -> {escapeKeyPressed(KeyCode.ESCAPE ,dialog );});
textState.setOnAction((event) -> {escapeKeyPressed(KeyCode.ESCAPE ,dialog );});
textloginName.setOnAction((event) -> {escapeKeyPressed(KeyCode.ESCAPE ,dialog );});
The problem is that the function doesn't get called.
Any idea how can I fix that? It's woth mentioning that the function by itself works fine if I replace the caller out of setOnAction();