I am developing a data entry GUI that has ~12 textfields the user enters data into, and then a "Save" button is clicked with the mouse to save that data.
I added a KeyEvent to make it so when the user presses "Enter", it also saves the data:
//Button Shortcut - Enter/Save
@FXML
public void handleEnterPressed(KeyEvent event) {
if (event.getCode() == KeyCode.ENTER) {
saveButton.requestFocus();
newCard(null);
event.consume();
}
}
This works - IF the save button is focused. For example, I click the save button, it saves the data. I press "Enter" - it saves the data again. If I tab through all the fields until the focus is back to the save button, it will save. But if, for example, my cursor is on one of the textfields and I hit "Enter" nothing happens. (newCard is the method that saves the textfield data to a list).
I made a new button in my controller:
@FXML private Button saveButton;
set the fx:id in Scene Builder to it and tried to use the .requestFocus(), but it doesn't seem to work. But it doesn't throw an error either so I'm not sure if I'm just using it incorrectly.