简体   繁体   English

Java-删除文件时显示进度条

[英]Java - Making progress bar while deleting files

I'm starting with Jframe and GUI stuff in Java and I want to make progress bar when program deleting files/folders. 我从Java中的JframeGUI东西开始,我想在程序删除文件/文件夹时显示进度条。
I wish I could make progress bar with % progress. 我希望我可以取得进度百分比的进度条。 When it start it'll be 0% and during deleting it'll goes to 100%. 开始时它将为0%,在删除过程中将变为100%。 Any ideas how to do that? 任何想法如何做到这一点? In some easy way? 以某种简单的方式?

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. 1)编写一种方法来计算要删除的所有文件夹和文件,如果您有多个嵌套的文件夹和文件,则可能必须递归调用此方法。

2)Set the maximum progress bar to this value via the setMaximum method. 2)通过setMaximum方法将最大进度条设置为此值。

3)Set the minimum to 0 via the progress bar setMinimum method. 3)通过进度条setMinimum方法将最小值设置为0。

4)Set "stringPainted" to true to actually display progress percentage. 4)将“ stringPainted”设置为true以实际显示进度百分比。

5)Finally (recursively if necessary) delete each file updating your progress bar via the setValue method. 5)最后(必要时递归)删除每个文件,通过setValue方法更新进度条。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM