如何实现进度条显示流程?

时间:2019-07-04 15:05:09

标签: java swing concurrency progress-bar

我正在开发一个重复文件查找器,并且当我按下“搜索”按钮时,我需要实现一个进度条才能看到“进度”。  我尝试了这个,但是它只显示0和100%。 这是搜索按钮中的代码:

private void cautaActionPerformed(java.awt.event.ActionEvent evt) {                         
    File file = fc.getSelectedFile();
    Map<String, List<String>> lists = new HashMap<>();
    find(lists, file);
    //Adresa unde aplicatia cauta duplicatele
    de.addElement("Caut fisiere duplicate in folderul : " + file.getName() + " cu locatia " + file.getParent());
    de.addElement("Dublu click pe fisier pentru a deschide folderul ");
    for (List<String> list : lists.values()) {
        if (list.size() > 1) {
            int progress = 0;
            while ( progress< 100) {
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {}
                pb.setValue(progress);
            }
            de.addElement("  ");
            de.addElement("Au fost gasite duplicate");
            for (String file1 : list) {
                de.addElement(file1);
            }
        }
    }
    de.addElement("  ");
}

0 个答案:

没有答案