JavaFx close window on pressing esc?

后端 未结 4 788
故里飘歌
故里飘歌 2021-01-12 18:59

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         


        
4条回答
  •  余生分开走
    2021-01-12 19:34

    Hope the imported Eventhandler package is not of JavaFX.

    Try using,

    import javafx.event.EventHandler;
    

    Note:As the naming convention are same but only the package name differs between swing and JavaFX, Your NetBeans/Eclipse may auto import different packages, so make sure of it.

提交回复
热议问题