Click here to Skip to main content
15,887,270 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a working program, which uses check boxes to let the user select specific directories, and after the user presses a button, the selected directories are cleared.

What I want to do now, is make the currently non-functional progress bar, fill up as the directories are being cleared. I've looked over the Java documentation on JProgressBar countless times, as well as watching countless tutorials on making and using a progress bar, but everything so far just shows how to manually set the value and message of the progress bar, and not how to assign it to an actual part of a task.

My question is, where would I put in the different commands for the progress bar, in order to make it a functional progress bar, rather than just a bar that fills up no matter what happens. For example, how would I make it, so that when a specific directory has a lot to delete, and it takes it a while, the progress bar starts to fill up more slowly? and vise versa for if a directory has almost nothing in it.

What I have tried:

I have not tried anything yet.
Posted
Updated 9-Jan-17 2:23am

1 solution

You have to calculate the rate of fill, based on the data you are trying to process. Most systems do this by continually sampling the data to get the ratio of processed to unprocessed, and the actual rate per second/minute etc.
 
Share this answer
 
Comments
Denisowator 12-Jan-17 7:08am    
That sounds very complex though. Would I have to do the calculation manually in the code, or is there something in Java that i can use?
Richard MacCutchan 12-Jan-17 8:09am    
Think about it: how would Java know what progress you have made in clearing certain files from your system? Obviously you must do the calculations yourself as your activity progresses. And it is not that difficult, just basic mathematics - how much work is complete vs how much work was there in total.
Denisowator 12-Jan-17 8:20am    
But how would I make the code know which part of the code is the process that the progress bar displays? That's what I'm stuck on.

I don't know how I would identify the code as a process for the progress bar in the first place.

Also, the processes for clearing the directories are in separate class files, which are called from a main class file. This is another reason I'm struggling to tell the program what the process is. I know how to call an external class, but how do I make a reference to it?
Richard MacCutchan 12-Jan-17 8:27am    
You just need to create a connection between the code that does the work and the code that displays the progress bar. Google can probably find you some examples.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900