3 Replies Latest reply: Jan 27, 2013 11:18 PM by jsmith RSS

    How to realize a splashscreen

    Rafal Z
      Because my application has to load some data, I would like to show a splahscreen with a ProgressIndicator before the main window shows. If I show my progressindicator in a new window (stage.showandwait()) and run following code in own thread:
      ProgressIndicator PIndicator=new ProgressIndicator();...
      for(double k=0.0;k<1.0;k+=0.01){
      then the ProgressIndicator works correctly but as soon as OwningStage.hide() is reached I get an Exception: java.lang.IllegalStateException: Not on FX application thread;
      If I try to show my stage with the ProgressIndicator by invoking the method show() after starting the thread, I get only a black rectangle.

      How to program such functionality correctly?

      with regards

      Rafal Ziolkowski
        • 1. Re: How to realize a splashscreen
          The preferred mechanism for this kind of functionality is to use a application preloader. The "Best Practices" documentation at http://docs.oracle.com/javafx/2/best_practices/jfxpub-best_practices.htm has an example of this.

          Also more information here: http://docs.oracle.com/javafx/2/deployment/preloaders.htm

          Edited by: James_D on Jan 27, 2013 7:00 AM
          • 2. Re: How to realize a splashscreen
            Rafal Z
            Thank you very much, that's it!


            Rafal Ziolkowski
            • 3. Re: How to realize a splashscreen
              Here is a splashscreen version I created a while back https://gist.github.com/1588531 . . . it doesn't follow the best practices of using a Preloader because I'm lazy . . . but still may perhaps be useful to you.

              Also click the download link off of the JavaFX samples showcase, download the sample source and open up the DataApp client application - it has a really nice Preloader screen of a car whizzing around a racetrack. http://www.oracle.com/technetwork/java/javafx/samples/index.html