【问题标题】:pregressBar in preloader does not update预加载器中的 pregressBar 不更新
【发布时间】:2016-02-14 17:41:31
【问题描述】:

我的预加载器中有这个:

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());
        }
    }

}

这在我的主要应用程序中。

    init (){
    //loading images
}

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

        }

但progressBar 并不laod。相反,它首先是 0.0 ,然后是 1.0 ,所以 pregressBar 已经满了。但我必须等待几秒钟。在这几秒钟之后,我的主应用程序启动了......

请帮忙:(

【问题讨论】:

    标签: java progress-bar javafx-8 splash-screen preloader


    【解决方案1】:

    同样的问题。 选中以通过init() 方法而不是start() 方法通知应用程序中的preloader

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

    它对我有用。试试看。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-11-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多