launcher: make modals closeable with esc key

This commit is contained in:
Bixilon 2020-11-04 14:42:52 +01:00
parent f9c791cf39
commit 95da6eb9e2
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4

View File

@ -29,6 +29,8 @@ import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.stage.Modality;
@ -79,6 +81,11 @@ public class MainWindow implements Initializable {
stage.close();
}
});
stage.addEventHandler(KeyEvent.KEY_PRESSED, (KeyEvent event) -> {
if (event.getCode() == KeyCode.ESCAPE) {
stage.close();
}
});
stage.show();
} catch (IOException e) {
e.printStackTrace();
@ -195,6 +202,12 @@ public class MainWindow implements Initializable {
stage.setTitle(LocaleManager.translate(Strings.SETTINGS_TITLE));
stage.getIcons().add(GUITools.logo);
stage.setScene(new Scene(parent));
stage.addEventHandler(KeyEvent.KEY_PRESSED, (KeyEvent event) -> {
if (event.getCode() == KeyCode.ESCAPE) {
stage.close();
}
});
stage.show();
} catch (IOException e) {
e.printStackTrace();