Custom Java splash screen freezes before loading entire application

I have a program that takes a long time to download. Because of this, I wanted to develop a screen saver that can provide feedback to the user about what is loading. Simple JFrame with image, label and JProgressBar.

I experimented, and the best results that I had do this in mine main():

SwingUtilities.invokeAndWait(new Runnable() {

    public void run() {

        new SplashScreen();
    }
});

SwingUtilities.invokeAndWait(new Runnable() {

    public void run() {

        //Code to start system
        new MainFrame();
        //.. etc
    }
});

Both SplashScreen and MainFrame are classes that extend the JFrame. I also use the substance as a library.

SplashScreen constructor adds JLabel and JProgressBar to itself, packages and installs visible. JProgressBar setIndeterminate(true);

, SplashScreen , ProgressBar , , , .

? , , , , " " .

+5
4

, , " " Swing. , ( ) , EDT, EDT. , :

SwingUtilities.invokeAndWait(new Runnable() {
    public void run() {
        new SplashScreen();
    }
});
// Code to start system (nothing that touches the GUI)
SwingUtilities.invokeAndWait(new Runnable() {
    public void run() {
        new MainFrame();
    }
});
//.. etc
+1

invokeAndWait Swing , . , 100% MainFrame.

, Splash SwingUtilities.invoke( | AndWait).

new Thread(new Runnable() { public void run() {
  // Create MainFrame here
  SwingUtilities.invokeLater(new Runnable() {
      public void run() {
         updateProgressHere();
      }
  });

  // Do other initialization
  SwingUtilities.invokeLater(new Runnable() {
      public void run() {
         updateProgressHere();
      }
  });
}).start(); 
+3

, .

, () .

, guis .

, .

, , , .

:

  • non-gui , (, ).
  • invokeLater, .
  • GUI invokeLater, , GUI.
  • ! GUI, .

-GUI- Thread.start, , "main"

GUI - , "invokeLater" , GUI ( , GUI, Swing).

- GUI, - , .

+3

, , Java6 , javaw java- ...

JVM , , , .

, , Winrun4J java launcher .

+1

All Articles