How to lock JavaFX fullscreen mode?

蹲街弑〆低调 提交于 2019-11-28 09:59:16

问题


I am currently working on a volunteer sign-in application, and need to prevent any attempts to tamper with the computer. As a start, I set the application to fullscreen, easily enough. Then I tried to set the exit key combination for the window to null, but JavaFX automatically defaults to the escape key in that case. I will have an admin section where the program can be exited using a password. Is there any way to effectively intercept any possible methods of exiting a JavaFX application's fullscreen state, or--better yet--temporarily suspend/lock other OS functions?

Edit--Using KeyCombination.NO_MATCH, I prevent the user from exiting fullscreen. However, the OS is still perfectly capable of exiting using standard key combos, or, in the case of OS X, simply by moving the mouse to the top of the screen and exiting using the program menu.


回答1:


I'm i missing something? i think its cheese.. like this

primaryStage.fullScreenProperty().addListener(new ChangeListener<Boolean>() {

        @Override
        public void changed(ObservableValue<? extends Boolean> observable,
                Boolean oldValue, Boolean newValue) {
            if(newValue != null && !newValue.booleanValue())
                primaryStage.setFullScreen(true);
        }
    });

fullscreen nobody tempers till user presses the start button to obscure the UI you can prevent that though- but i will suggest try the following code only if you are about to off your pc

new Thread(new Runnable() {
        @Override
        public void run() {
            while(true){
               //in my initial try i didn't add sleep, 
               //and i ended up,turning off the pc,lost this post for a while
                try {
                    Thread.sleep(100); //buy little millieseconds
                } catch (InterruptedException e) {}

                Platform.runLater(()->{
                    primaryStage.toFront();
                    //bring your UI on top of everyone
                });
            }

        }
    }).start();

primaryStage is your Stage

Hope its what you want




回答2:


primaryStage.setFullScreenExitKeyCombination(KeyCombination.NO_MATCH);



来源:https://stackoverflow.com/questions/32282646/how-to-lock-javafx-fullscreen-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!