How to make my Java destop application show an image before it starts?
-
19-09-2019 - |
Question
I'm using NetBeans IDE 6.8 (Mac Version). which tool of their GUI builder will assist me in doing this?
What I want is is to show the user an image while my application is loading for couple of seconds before I show him the application. How can I do that? initializing
Solution
If you have Java 6 installed, checkout the Splash-Screen tutorial.
OTHER TIPS
actually, you can do that by using the -splash flag in the java program... for example, you want to show the image splash.jpg when you run main.class,
so what you will do is,
java -splash:pathoftheimage/splash.jpg main
As you're running on a MAC you probably won't have access to Java 6 and so will have to build the splashscreen yourself. You should run code similar to the following early in your initialisation cycle (i.e. so that the splashscreen dialog is displayed for the maximum amount of time).
JDialog dlg = new JDialog();
// Remove dialog decorations to make it look like a splashscreen.
dlg.setUndecorated(true);
dlg.setModal(true);
dlg.setLayout(new BorderLayout());
// Load image.
ImageIcon img = new ImageIcon(getClass().getResource("/foo/bar/splash.png");
// Add image to center of dialog.
dlg.add(img, BorderLayout.CENTER);
dlg.setLocationRelativeTo(null);
dlg.setVisible(true);
// ... Perform application initialisation here.
// Initialisation complete so hide dialog.
dlg.setVisible(false);
dlg = null;
If you are using NetBeans
... then don't worry NetBeans
has solved this problem for you.
Right Click
On yourProject
after opening it.- Go to
properties
- Click
Application
- There will be
Splash Screen
,Browse
your image which you want to show.
As shown in Pictures below
When you will do this , your image
will show but you will not be able to see this. To See it, you have to delay time
of appearence
of next window
. For this do these steps.
- Go to your
JFrame code
area which you want to show next. - In
Main Fun
there will berun
fun. Inside
run
function just write the following code.try{
Thread.sleep(time in milisecond just like 4200);
//
Create Next Frame Object Here
}catch(Exception ex) { }