Creating a REAL Splash Screen in Java using NetBeans IDE

Two weeks earlier, I posted an article on how to Create a Splash Screen in Java using NetBeans IDE that showed how to convert a animated gif into a splash screen for your java app. But some readers asked that it was not what they were looking and they want to learn how to create a real splash screen and I think by real they meant showing a progress bar while they load some resources in the background (make their app ready to use). So here I am with the video tutorial for the same.

Although, I made two part long video tutorial but still it wasn’t enough to demonstrate all things I wanted. So, here are some more tips that I would like to share in a question and answer form.

Q The progress bar only fills to half (even in the video).
A Sorry, my fault! It was because I looped it only for 5 times. The progress must be relative to how much time you are looping. So to correct, either you can loop it 5 more times i.e 10 or you can change this statement –

int doneProg = prog*width/50;

I have corrected it in the final project.

Q How can I change the font for the text in loadingTextArea?
A Create a new font variable –

public static Font myfont;

Now in the loadingMethod() below the line: loadingGraphics = loadingScreen.createGraphics(); do the following:

myfont = new Font(“TimesRoman”, Font.BOLD, 14);
loadingGraphics.setFont(myfont);

Q How can I place my progressArea at the right side of the image base-aligned with my textArea?
A Just change the placement for loadingProgressArea in the loadingMethod() to:

loadingProgressArea = new Rectangle2D.Double(wd*0.55, ht*0.7, wd*0.4, 25);

Q The splash screen is automatically centered, but my form opens in the top left corner. How can I make my form open in the center of the screen?
A Right Click your form>Events>windowOpened and paste the following code-

this.setLocationRelativeTo(null);

Q The doneProgress doesn’t cover the whole of progressArea, it seems a pixel above the bottom edge. How can I correct this?
A Replace the fillRect() line in the loadingProgress() method with this:

loadingGraphics.fillRect(x, y+1, doneProg, height);

You can download the whole Netbeans project from here.

If you have any other query you can comment and I would just expand this Q/A list.

Don’t forget sharing is caring!!

10 thoughts on “Creating a REAL Splash Screen in Java using NetBeans IDE”

Leave a Comment

Your email address will not be published. Required fields are marked *