Solved

Progress Bar

Posted on 2004-09-03
17
317 Views
Last Modified: 2010-03-31
I have main method which contains the follwoing code
       
         
         if (loginIns.isValidUser()) {
            //Instantiate the Splash Screen after successfull login
            SplashScreen s = new SplashScreen(Image.getIcon("icon"), new Frame());

            logger.info("Validated");
            AD.getInstance();
            A.initData();
            //initialises all the PanelControllers

            PFactory.getInstance().initialise();
            Fer.getInstance();
//      .. number of other things are instantiated

            UserInterfaceManager uiManager = new UserInterfaceManager();
            Util.setAppFrame(uiManager);
            uiManager.initialize();

            // close Splash Screen
             s.closeSplashScreen();
        }

Under the Splash Screen i want to display a progress bar which automatically closes when the splash screen closes (that is the application loads).
How can i do this?
plz help
0
Comment
Question by:thomas908
  • 5
  • 4
  • 4
  • +3
17 Comments
 
LVL 35

Expert Comment

by:girionis
Comment Utility
Should the progress bar not close automatically when it finishes?
0
 
LVL 8

Author Comment

by:thomas908
Comment Utility
>> Should the progress bar not close automatically when it finishes?
Yes it should
0
 
LVL 6

Expert Comment

by:expertmb
Comment Utility
it will close once u close the window.
0
 
LVL 6

Expert Comment

by:expertmb
Comment Utility
if you are adding the progress bar to splashscreen, when the splash screen closes, progressbar will also close.
0
 
LVL 35

Expert Comment

by:girionis
Comment Utility
So what's the problem? You do not know how to create a JProgressBar?
0
 
LVL 6

Expert Comment

by:expertmb
Comment Utility
0
 
LVL 6

Expert Comment

by:expertmb
Comment Utility
0
 
LVL 3

Expert Comment

by:CI-Ia0s
Comment Utility
This should help: http://java.sun.com/docs/books/tutorial/uiswing/components/progress.html

Note that if you start any processes from a GUI (i.e. via an actionListener, etc.) during the time that the progress bar is monitoring, they'll need to be started in a separate thread.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 3

Expert Comment

by:CI-Ia0s
Comment Utility
Beaten... :(
0
 
LVL 8

Author Comment

by:thomas908
Comment Utility
>> if you are adding the progress bar to splashscreen, when the splash screen closes, progressbar will also close.
How to add progress bar to splash screen?
splash screen is a image
:(
0
 
LVL 35

Expert Comment

by:girionis
Comment Utility
What is this class: SplashScreen

You should add the progress bar in there.
0
 
LVL 37

Expert Comment

by:zzynx
Comment Utility
>> splash screen is a image
You mean your splash screen mainly *contains* an image.
It's probably a JPanel/JDialog in which you can add your progress bar.
(Probably BorderLayout, with the image in the CENTER and the progress bar in the SOUTH)
0
 
LVL 35

Accepted Solution

by:
girionis earned 500 total points
Comment Utility
This is a modified example from javaworld (http://www.javaworld.com/javaworld/javatips/jw-javatip104.html) that is working. Modify it to fit your own needs:

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;

class SplashWindow3 extends JWindow
{
      public static void main(String [] arguments)
      {
            new SplashWindow3("figure4.gif", new JFrame(), 10000);
      }
      
    public SplashWindow3(String filename, JFrame f, int waitTime)
    {
        super(f);
        JLabel l = new JLabel(new ImageIcon(filename));
        getContentPane().add(l, BorderLayout.CENTER);
        pack();
        Dimension screenSize =
          Toolkit.getDefaultToolkit().getScreenSize();
        Dimension labelSize = l.getPreferredSize();
        setLocation(screenSize.width/2 - (labelSize.width/2),
                    screenSize.height/2 - (labelSize.height/2));

        addMouseListener(new MouseAdapter()
            {
                public void mousePressed(MouseEvent e)
                {
                    setVisible(false);
                    dispose();
                }
            });

                  
            final JProgressBar progress = new JProgressBar();
            progress.setIndeterminate(true);
            progress.setSize(10, 10);
        progress.setLocation(0, 10);
        getContentPane().add(progress, BorderLayout.NORTH);
            

        final int pause = waitTime;
        final Runnable closerRunner = new Runnable()
            {
                public void run()
                {
                    setVisible(false);
                    dispose();
                }
            };
        Runnable waitRunner = new Runnable()
            {
                public void run()
                {
                    try
                        {
                            Thread.sleep(pause);
                            SwingUtilities.invokeAndWait(closerRunner);
                        }
                    catch(Exception e)
                        {
                            e.printStackTrace();
                            // can catch InvocationTargetException
                            // can catch InterruptedException
                        }
                }
            };
        setVisible(true);
        Thread splashThread = new Thread(waitRunner, "SplashThread");
        splashThread.start();
    }
}
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
> How to add progress bar to splash screen?
> splash screen is a image

Use a JLabel to display your image, and either add your progress bar to the panel containing the label or to the label directly depending on where you want it to appear.

0
 
LVL 8

Author Comment

by:thomas908
Comment Utility
Thanks You so much
0
 
LVL 8

Author Comment

by:thomas908
Comment Utility
sorry typo ;)
*Thank You so much
0
 
LVL 35

Expert Comment

by:girionis
Comment Utility
Thank you for accepting :)
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now