I am working on making a GUI for a program that I had written a while back. I wanted to include a progress bar to show its progress. However, the progress bar does not refresh and show the current percentage, it merely stays blank until the program is finished at which time it shows 100%. How do I make it to where it shows real time progress?
Here is my current code of the particular section of the GUI:
private void beginSortButtonActionPerformed(java.awt.event.ActionEvent evt) { //Variables Scanner s = new Scanner(System.in); String warningMessage = "WARNING!: Organizing files can be somewhat dangerous." + "\n" + "Do you wish to continue? (y/n) : "; String userConfirmation; String currentDirectoryPath; String RootPath; String goAgain = "y"; String goAgain2; Receipt[] sortedReceipts; ArrayList<Receipt> tempArrayList = new ArrayList<>(); Vector filePaths = new Vector<String>(); int value = 0; currentDirectoryPath = this.currentDirectory.getText(); RootPath = this.rootPath.getText(); Path p = Paths.get(currentDirectoryPath); DirectoryStream<Path> dir = null; try { dir = Files.newDirectoryStream(p); } catch (IOException ex) { Logger.getLogger(fileSortWindow.class.getName()).log(Level.SEVERE, null, ex); } Path newDir = Paths.get(RootPath); try { Files.createDirectories(newDir); } catch (IOException ex) { Logger.getLogger(fileSortWindow.class.getName()).log(Level.SEVERE, null, ex); } for (Path file : dir) { String name = file.getFileName().toString(); if (name.endsWith(".receipt")) { //String representation of the files directory. String fileDir = currentDirectoryPath.toString() + "\\" + name; filePaths.add(fileDir); //Making new Receipt object and getting the info from the methods in order to sort into the directories. Receipt newReceipt = null; try { newReceipt = new Receipt(fileDir); } catch (FileNotFoundException ex) { Logger.getLogger(fileSortWindow.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(fileSortWindow.class.getName()).log(Level.SEVERE, null, ex); } String firstName = newReceipt.getCustomerFirstName(); String lastName = newReceipt.getCustomerLastName(); String year = Integer.toString(newReceipt.getYear()); String month = Integer.toString(newReceipt.getMonth()); String wholeName = lastName + ", " + firstName; //Progress bar. progress.setValue(value); progress.repaint(); //Creates the new path for the file. Path tempDir = Paths.get(RootPath, wholeName, year, month); try { Files.createDirectories(tempDir); } catch (IOException ex) { Logger.getLogger(fileSortWindow.class.getName()).log(Level.SEVERE, null, ex); } //Adds 1 to the progress bar. value++; Path newPath = Paths.get(tempDir.toString(), name); if (Files.notExists(newPath)) { try { Files.copy(file, newPath); } catch (IOException ex) { Logger.getLogger(fileSortWindow.class.getName()).log(Level.SEVERE, null, ex); } } } } this.output.setText("Done."); }