TextArea may not be thread-safe

This commit is contained in:
Lucas Alber
2019-02-27 15:27:19 +01:00
parent add3e23a00
commit 4ea716be6c

View File

@@ -32,7 +32,7 @@ public class Main {
JPanel mainPanel = new JPanel(); JPanel mainPanel = new JPanel();
mainPanel.setBorder(new TitledBorder(new EtchedBorder(), "Process:")); mainPanel.setBorder(new TitledBorder(new EtchedBorder(), "Process:"));
JTextArea textArea = new JTextArea(16, 58); final JTextArea textArea = new JTextArea(16, 58);
textArea.setEditable(false); textArea.setEditable(false);
JScrollPane scroll = new JScrollPane(textArea); JScrollPane scroll = new JScrollPane(textArea);
scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
@@ -71,7 +71,9 @@ public class Main {
.parallelStream() .parallelStream()
.forEach(p -> { .forEach(p -> {
if (aborted) return; if (aborted) return;
textArea.append("Processing: " + p.getFileName().toString() + "\n"); synchronized (textArea) {
textArea.append("Processing: " + p.getFileName().toString() + "\n");
}
Image img = new Image(p.toFile()); Image img = new Image(p.toFile());
img.rotate(); img.rotate();
img.saveAs(p.toFile()); img.saveAs(p.toFile());