Solved

Using a JProgressBar

Posted on 2004-09-26
4
343 Views
Last Modified: 2008-02-01
hello!

I want to use a JProgressBar in a splash screen of a java program i am writing. The program at the start reads some text files, processes them etc. I want to indicate how much of the processing is done by using a JProgressBar, so the user essentially knows how much is left before the main GUI part of the app shows.

How can i determine the length of the task? How is it usually done, currently, the only way i am aware of tackling this problem is to increment the progress bar by 1 in different locations of the code untill i finally have incremented to 100 (the max value of the JProgressBar i want to use) at the end of the task. To me this seems tedious and very unprofessional, i was wondering how professional java developers would indicate how much of a task is complete using a JProgressBar.

Thx for any tips or help.
0
Comment
Question by:Mr_A_Smith
  • 2
  • 2
4 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 12154386
If the length of the processing is not known, you'll have to setDeterminate(false) on the JProgressBar
0
 
LVL 5

Accepted Solution

by:
TrekkyLeaper earned 30 total points
ID: 12154387
The way I have done it involves a couple steps:

1. You need to come up with some sort of metric for measuring your progress. This may be something like files loaded / total files, distinct loading operations / total, etc.
2. Once you have that, I would make the splash screen (or a subclass of the progress bar would be even better) an Observer of your loading system.

Observer: http://java.sun.com/j2se/1.4.2/docs/api/java/util/Observer.html
Observable: http://java.sun.com/j2se/1.4.2/docs/api/java/util/Observable.html
Java Almanac: http://javaalmanac.com/egs/java.util/Obs.html

Then, whenever your loading model reaches a new checkpoint, you can do something like:

setChanged();
notifyObservers( new Integer( myProgress ) );
clearChanged();

In the Observer's update method, the Integer passed in will be the second argument. You can take that and adjust the progress bar.

I hope this makes sense.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12154389
Or rather

setIndeterminate(true);

0
 
LVL 5

Expert Comment

by:TrekkyLeaper
ID: 12155280
=)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

820 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