Solved

Using a JProgressBar

Posted on 2004-09-26
4
339 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Unable to open debugger port in Intellij idea 6 140
what is the difference between "sudo su" and "su - root" 6 104
advertisement module in core php 4 144
tomcat not starting 6 26
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
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 …
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

911 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

23 Experts available now in Live!

Get 1:1 Help Now