0

I'm writing a java swing application which uses external resource files.
Many of the resource files are only necessary to load with certain selections.
Upon making a selection, the first window closes, the appropriate external resources are loaded, and another window opens with the resources.

The first window has a splash screen to cover the loading time.
How can I make the second window have something similar?
What I've seen involves a task occurring in the same window, which isn't viable for this project, and the Java's built-in splash screen won't start a second time (SplashScreen.getSplashScreen returns null).

Community
  • 1
  • 1
  • 1
    possible duplicate of [Connect JProgressBar with download process](http://stackoverflow.com/questions/9420778/connect-jprogressbar-with-download-process) – Andrew Thompson Oct 15 '13 at 05:35

2 Answers2

2

In OtrosLogViewer I display first splash screen defined in MANIFEST.MF. When application is loading I render new splashscreen according to loading progress. OtrosSplah.java is calling method render to repaint splash:

  private static void render() {
      SplashScreen splashScreen = SplashScreen.getSplashScreen();
      if (splashScreen == null) {
        return;
      }
      Graphics2D g = splashScreen.createGraphics();
      if (g == null) {
        return;
      }

      if (version == null) {
        try {
          version = VersionUtil.getRunningVersion();
        } catch (IOException e) {
          version = "?";
        }
        version = "Version: " + version;
      }

      g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      g.setComposite(AlphaComposite.Clear);
      Rectangle bounds = splashScreen.getBounds();
      g.fillRect(0, 0, bounds.width, bounds.height);
      g.setPaintMode();
      g.setColor(Color.BLACK);
      g.setFont(g.getFont().deriveFont(14f));
      g.drawString(message, 20, 110);
      g.drawString(version, 20, 130);
      splashScreen.update();
    }

You can do the same. Display first splash screen from MANIFEST.MF and later paint new one.

KrzyH
  • 4,256
  • 1
  • 31
  • 43
1

Instead of using the SplashScreen API, you could simply create yourself a JWindow.

Into this you can either add a bunch of components to provide the functionality you need (ie a JLabel for the background, a JLabel for the message) and make it visible while you're loading your resources.

When you done, you can simply dispose of the window.

Also, make sure, you're performing all you loading in a background thread. SwingWorker would be good for this purpose, IMHO

This answer demonstrates the concept, seek the second example...

Community
  • 1
  • 1
MadProgrammer
  • 343,457
  • 22
  • 230
  • 366