Solved

Using a JProgressBar

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
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 …

813 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

11 Experts available now in Live!

Get 1:1 Help Now