2016-02-14 14 views
0

我有這個在我的預載: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()); 
     } 
    } 

} 

,這在我的主 - 應用。

init(){ 
    //loading images 
} 

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

     } 

但是progressBar並不存在。相反,它先是0.0,然後是1.0,所以pregressBar已經滿了。但我必須等待幾秒鐘。這些幾秒鐘,我的主應用程序啓動後...

請幫助:(

回答

0

同樣的問題在這裏。 檢查在應用程序從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)); 

} 

它適用於我。試試看。