private void fetchLocalLog() { // todo: when the log is very very large, this fails with OutOfMemoryError final File logFile = new File(outputDirectory, selectedTask.getOutput() + ".log"); logTab.setTitleAt(1, "Local log: " + logFile.getName()); if (logFile.exists()) { Thread thread = new Thread( new Runnable() { public void run() { final StringBuilder logText = new StringBuilder(); try { BufferedReader in = new BufferedReader(new FileReader(logFile)); String line; while ((line = in.readLine()) != null) { logText.append(line); logText.append("\n"); } } catch (IOException e) { logText.append("Cannot load: ").append(logFile.getAbsolutePath()); logText.append(e.toString()); } SwingUtilities.invokeLater( new Runnable() { public void run() { localLog.setText(logText.toString()); } }); } }); thread.start(); } else { localLog.setText("No log found: " + logFile.getAbsolutePath()); } }