Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Progress Bar

Posted on 2004-09-03
17
Medium Priority
?
322 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 4
  • +3
17 Comments
 
LVL 35

Expert Comment

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

Author Comment

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

Expert Comment

by:expertmb
ID: 11971757
it will close once u close the window.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Expert Comment

by:expertmb
ID: 11971783
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
ID: 11971784
So what's the problem? You do not know how to create a JProgressBar?
0
 
LVL 6

Expert Comment

by:expertmb
ID: 11971793
0
 
LVL 3

Expert Comment

by:CI-Ia0s
ID: 11971824
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
 
LVL 3

Expert Comment

by:CI-Ia0s
ID: 11971830
Beaten... :(
0
 
LVL 8

Author Comment

by:thomas908
ID: 11972023
>> 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
ID: 11972047
What is this class: SplashScreen

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

Expert Comment

by:zzynx
ID: 11972376
>> 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 2000 total points
ID: 11972589
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
ID: 11977466
> 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
ID: 11978947
Thanks You so much
0
 
LVL 8

Author Comment

by:thomas908
ID: 11978949
sorry typo ;)
*Thank You so much
0
 
LVL 35

Expert Comment

by:girionis
ID: 11980952
Thank you for accepting :)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

722 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