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

x
?
Solved

Using a JProgressBar

Posted on 2004-09-26
4
Medium Priority
?
353 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
[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
  • 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 120 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
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…
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses

661 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