File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes How to get length of task for JProgressbar? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to get length of task for JProgressbar?" Watch "How to get length of task for JProgressbar?" New topic
Author

How to get length of task for JProgressbar?

Bob Zoloman
Ranch Hand

Joined: Jul 02, 2006
Posts: 72
Hi, I am trying to figure out how to implement a JProgressbar, but I'm a little confused on the part where you get the length of the a long running task, and the currentTime() of the task. If I want to use a progressbar for a certain class do I need to have those kinds of methods inside the class that has that task? It seems like I would have to repeat a lot of code in all classes that need a progress bar. Is there a better way to do it? Thanks in advance.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

Estimating the amount of time that a task will take is, obviously, a hard (read impossible) problem. Does using a progress bar mean duplicating code? Well, yeah, kinda. If you want "X% done" kind of progress bars, then every long-running task has to periodically send an event which says "I'm X% done."


[Jess in Action][AskingGoodQuestions]
Bob Zoloman
Ranch Hand

Joined: Jul 02, 2006
Posts: 72
Say for example I had 10 separate classes, and each one has a task I want to have a progress bar for, the way I understand it is that I would need a getLengthofTask(), getCurrentTime(), methods plus all the instance variables required for progress bar, etc... embedded in every single class that uses one (in this case 10).

To me it seems like a really bad design... First, it reduces your classes reusablility, and you have duplicate code in every class. Is there a better design approach I could take?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to get length of task for JProgressbar?
 
Similar Threads
JProgressBar - Please Help
JProgressBar and Determining Task Length
Finding rowcount for large files, Reading pipe delimited file
Learning to use JProgressBar, having some problems. Need some help here.
Suggestions on making a progress bar/waiting message