Reputation: 1321
I'm using a process builder to run batch files, and I'm trying to get a progress bar and textarea to update after each batch file completes.
The problem is, the progress bar and text area don't get updated until all three batch files have completely finished, then it only displays the last update to the progress bar and text area (I'm guessing its doing them all at once and the last progressbar.setValue over rides the prior values)
here is one of the methods for running one of the three batch files:
public void runBatch1() {
try {
ProcessBuilder builder = new ProcessBuilder("cmd.exe", "/c", "cd \"C:\\batchfiles\" && batch1.bat");
builder.redirectErrorStream(true);
Process p = builder.start();
BufferedReader r = new BufferedReader(new InputSteamReader(p.getInputStream()));
String line;
while (true) {
line = r.readLine();
if (line == null) {
break;
}
System.out.println(line);
jTextArea1.setText("Batch one finished.");
jProgressBar1.setValue(33);
}
} catch (Exception e) {
e.printStackTrace();
}
}
Upvotes: 0
Views: 65
Reputation: 549
I think you might just need to switch to the event dispatch thread: progressbar in a thread does not update its UI until the work was done in the main thread
Upvotes: 1