Im calling a new stage in my program which I like to close on pressing escape. I did this which gives me a NullPointerException:
scene.setOnKeyPressed(ne
Add the event handler to the stage/window you want to close on ESC.
JavaFX 8 style:
stage.addEventHandler(KeyEvent.KEY_RELEASED, (KeyEvent event) -> { if (KeyCode.ESCAPE == event.getCode()) { stage.close(); } });