I'm starting with Jframe
and GUI
stuff in Java and I want to make progress bar when program deleting files/folders.
I wish I could make progress bar with % progress. When it start it'll be 0% and during deleting it'll goes to 100%. Any ideas how to do that? In some easy way?
Asked
Active
Viewed 780 times
0
-
Check this question, maybe helps you: [How to add a progress bar](http://stackoverflow.com/questions/8916064/how-to-add-a-progress-bar) – Pichi Wuana Jul 12 '15 at 15:19
-
It gave me a lead. Thanks anyway! – Bukk94 Jul 28 '15 at 22:13
1 Answers
0
The simplest way to do it would be to:
1)write a method to count all folders and files you want to delete, you may have to call this method recursively where you have multiple nested folders and files.
2)Set the maximum progress bar to this value via the setMaximum method.
3)Set the minimum to 0 via the progress bar setMinimum method.
4)Set "stringPainted" to true to actually display progress percentage.
5)Finally (recursively if necessary) delete each file updating your progress bar via the setValue method.

Giles Thompson
- 1,097
- 1
- 9
- 24
-
Can I use this? new File("/path/to/folder").listFiles().length; to count number of files? – Bukk94 Jul 12 '15 at 18:45
-
yes you can, but like I say where the folder also contains folders with files in then you will need to call listFiles on those folders too . – Giles Thompson Jul 12 '15 at 23:57
-
-
-
So I finally managed to do it. I followed this simple manual and everything worked fine. I had a few problems with swing and multithreating but I solve that. This helped me a lot. Thanks. – Bukk94 Jul 28 '15 at 22:14