如何加载的JavaFX initialize()方法时在后台大文件? [英] How to load big file in background during initialize() method of Javafx?

查看:761
本文介绍了如何加载的JavaFX initialize()方法时在后台大文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

应用程序的初始化过程中,我的JavaFX桌面应用负载和大的文本文件中的

My javafx desktop application load and big text file during the initialization of the application in the

 @Override
    public void initialize(URL url, ResourceBundle rb) {

      loadAppConfigurationFile();
   }


   private void loadAppConfigurationFile() {

        Task<Void> task = new Task<Void>() {
            @Override
            public Void call() throws InterruptedException {

                //read file and do some operation
                return null;
            }
        };
        new Thread(task).start();
    }

但这里的问题是我的应用程序界面没有出现,直到这个过程过来。我调用这个文件中读取另一个线程,不同的是我的GUI阶段/场景将被加载第一,他们直到该文件是在系统加载我可以显示一些加载消息。

But the problem here is my application GUI doesn't appear till this process it over. I invoked this file reading in another thread excepting that my GUI stage/scene will be loaded first and their I can show some loading message till that file is loaded in the system.

请告知确切的解决方法此。

Kindly tell the exact workaround for this.

推荐答案

我尝试这一点,它的工作很容易......这里的酒吧是一个进度条

i try this and its work easily...here bar is a progress bar

@FXML
void initialize() {
    assert bar != null : "fx:id=\"bar\" was not injected: check your FXML file 'Check.fxml'.";
    loadAppConfigurationFile();
}

private void loadAppConfigurationFile() {
    Task task = new Task<Void>() {
@Override public Void call() throws InterruptedException {
     int max = 1000000;
    for (int i=1; i<=max; i=i+10) {
        if (isCancelled()) {
           break;
        }
        updateProgress(i, max);
        System.out.println("somethings is here");
    }
    return null;
}
};
bar.progressProperty().bind(task.progressProperty());
new Thread(task).start();
}

这篇关于如何加载的JavaFX initialize()方法时在后台大文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆