I have not found a direct way to assign a keyboard shortcut to a button type in a JavaFx 8 dialog.
For instance:
dialog.dialogPane().getButtonTypes.addAll(ButtonType.OK, ButtonType.Cancel)
How can I assign the ESC key to ButtonType.Cancel ?
Thanks.
You can use an accelerator as demonstrated in:
JavaFX dialogs are a bit weird (and complicated) in the way they define and use buttons, so adding the accelerator gets a little convoluted, but is still possible. The code below sets up an accelerator to fire the button action when a key combination is pressed, shortcut+f, where the shortcut key will change depending on your OS (on OS X it is the key labeled "command").
Executable Sample Code
Most of this code is just lifted from the excellent Makery JavaFX dialog tutorial. Additional code was added to the tutorial code to add the fishing button and the accelerator to trigger it.
Dialog before accelerator triggered:
Dialog after accelerator triggered: