I need to listen to key events in stage but not when the FileChooser is displayed.
Is there a way to stop KeyEvent (e.g. Esc key is pressed.) propagation to (parent) Stage, when FileChooser is displayed?
OR
Detect that the KeyEvent is propagated from FileChooser?
class KeyEventTest extends Application
{
@Override
public void start(Stage stage) throws Exception
{
Button browseBtn = new Button("Browse File System");
browseBtn.setOnAction(ae ->
{
FileChooser fileChooser = new FileChooser();
fileChooser.showOpenMultipleDialog(stage);
});
stage.setScene(new Scene(new BorderPane(browseBtn), 500, 200));
stage.setTitle("Test");
stage.addEventHandler(KeyEvent.KEY_RELEASED, keyEvent ->
{
// Do not trigger when Esc key is pressed on FileChooser
KeyCode keyCode = keyEvent.getCode();
System.out.println(keyCode);
});
stage.centerOnScreen();
stage.show();
}
public static void main(String[] args)
{
launch(args);
}
}