Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在可运行的runnable中如何隐藏JavaFX组件?_Java_Concurrency_Runnable - Fatal编程技术网

在可运行的runnable中如何隐藏JavaFX组件?

在可运行的runnable中如何隐藏JavaFX组件?,java,concurrency,runnable,Java,Concurrency,Runnable,我正试图解决一个并发问题。当我单击一个按钮登录到我的系统时,我会执行一项检查,查看用户是否有正确的权限登录,如果他们有权限,则会填充我的数据模型,并将用户转发到“仪表板” 为了改进UI的人机交互,我想切换微调器UI元素的显示和隐藏,这样用户就不会认为在后台任务运行时系统已经冻结 我目前正在可运行的服务器上处理此登录脚本: loginBtn.setOnMouseClicked(new EventHandler<MouseEvent>() { @Overr

我正试图解决一个并发问题。当我单击一个按钮登录到我的系统时,我会执行一项检查,查看用户是否有正确的权限登录,如果他们有权限,则会填充我的数据模型,并将用户转发到“仪表板”

为了改进UI的人机交互,我想切换微调器UI元素的显示和隐藏,这样用户就不会认为在后台任务运行时系统已经冻结

我目前正在可运行的服务器上处理此登录脚本:

        loginBtn.setOnMouseClicked(new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent mouseEvent) {

            // Try to verify the user with the provided credentials
            // run this on a new thread as it takes 5-10 seconds to compute
            new Thread(new Runnable() {
                @Override
                public void run() {

                    // Set the credentials to pass
                    String username = txtUsername.getText();
                    String password = txtPassword.getText();

                    if(verifyUser(username, password)){

                        // Set the loggedIn variable to true (singleton db connection)
                        ScreensFramework.connected = true;

                        // Check we build the system successfully (returns boolean)
                        if(ScreensFramework.authenticated()){
                            hideSpinner();
                            goToDashboard(new ActionEvent());
                        }
                    } else {
                        // there was an error with the connection
                        hideSpinner();
                        setError(error);
                    }
                }
            }).start();
        }
    });
我遇到的问题是,我无法在runnable中调用hideSpinner(),这是为什么?我如何在线程运行时让组件进行更新

提前感谢,,
Alex。

对于当前设置,请使用runLater在JavaFX应用程序线程上操作UI

Platform.runLater(()->spinnerWrap.setVisible(false));

您应该为您的非JavaFX线程逻辑使用a,然后,而不是使用runLater,您可以将spinner visible属性绑定到task running属性。

ah Jewelsea,我很高兴看到您的响应,因为您是我最喜欢的JavaFX相关线程的响应者之一-任务实现非常有效,非常感谢!)
Platform.runLater(()->spinnerWrap.setVisible(false));