preloader中的pregressBar不会更新 [英] pregressBar in preloader does not update

查看:83
本文介绍了preloader中的pregressBar不会更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的预加载器中有这个

import javafx.application.Preloader;
import javafx.scene.Scene;
import javafx.scene.control.ProgressBar;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;

public class SplashScreenView extends Preloader {

    ProgressBar bar;
    Stage stage;
    // boolean noLoadingProgress = true;

    public Scene createPreloaderScene()
    {
        bar = new ProgressBar();
        BorderPane borderPane = new BorderPane();
        borderPane.setCenter(bar);
        return new Scene(borderPane, 500, 150);
    }

    public void start(Stage stage) throws Exception
    {
        this.stage = stage;
        stage.setScene(createPreloaderScene());
        stage.show();

    }

    @Override
    public void handleStateChangeNotification(StateChangeNotification info)
    {
        if (info.getType() == StateChangeNotification.Type.BEFORE_START)
        {
            stage.hide();
        }
    }

    @Override
    public void handleProgressNotification(ProgressNotification pn)
    {
        bar.setProgress(pn.getProgress());
        System.out.println("Progress " + bar.getProgress());
    }

    @Override
    public void handleApplicationNotification(PreloaderNotification arg0)
    {
        if (arg0 instanceof ProgressNotification)
        {
            ProgressNotification pn = (ProgressNotification) arg0;
            bar.setProgress(pn.getProgress());
            System.out.println("Progress " + bar.getProgress());
        }
    }

}

,这在我的主-Application中.

and this in my main -Application.

    init (){
    //loading images
}

    public static void main(String[] args){
            LauncherImpl.launchApplication(Main.class, SplashScreenView.class, args);

        }

,但progressBar不起作用.相反,它首先是0.0,然后是1.0,因此pregressBar已经满了.但我必须等待几秒钟.这几秒钟后,我的主应用程序启动了...

but the progressBar does not laod. instead, it is first 0.0 and then 1.0 , so the pregressBar is already full. but I have to wait for some seconds. after these some seconds my main-Application starts...

请帮助:(

推荐答案

此处存在相同问题. 检查是否通过init()方法而不是通过start()方法通知应用程序中的preloader.

Same problem here. Check to notify the preloader in application from init() method and not from start() method.

@Override
public void init() throws Exception {
    // do some heavy stuff
    notifyPreloader(new ProgressNotification(0.5));
    // do some heavy stuff
    notifyPreloader(new ProgressNotification(0.8));

}

对我有用.试试吧.

这篇关于preloader中的pregressBar不会更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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