This discussion is archived
3 Replies Latest reply: Jan 27, 2013 9:18 PM by jsmith RSS

How to realize a splashscreen

Rafal Z Newbie
Currently Being Moderated
Hallo,
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){
   PIndicator.setProgress(k);
   Thread.sleep(100);
}    
if(OwningStage!=null){
   OwningStage.hide();
}
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
    James_D Guru
    Currently Being Moderated
    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 Newbie
    Currently Being Moderated
    Thank you very much, that's it!

    greetings

    Rafal Ziolkowski
  • 3. Re: How to realize a splashscreen
    jsmith Guru
    Currently Being Moderated
    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

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points