Ho fatto come hai detto tu, adesso il programma no si blocca, ed il testo viene visualizzato, ma non compare la jprogressbar di attesa.
Nel metodo dove devo aprire il file ho scritto:
La classe MyProgressBar è la seguente:codice:MyProgressBar m = new MyProgressBar(frame, editor, fileAbsPath); m.run();
codice:package it.mditor.listeners.filemenu; import it.editor.graphics.TextEditor; import it.editor.main.BuildEditor; import java.io.FileInputStream; import java.io.InputStream; import javax.swing.ProgressMonitorInputStream; public class MyProgressBar extends Thread { private BuildEditor frame; TextEditor editor; String fileAbsPath; public MyProgressBar (BuildEditor frame, TextEditor editor, String fileAbsPath) { this.frame = frame; this.editor = editor; this.fileAbsPath = fileAbsPath; } public void run() { try { // open the file, wrapping it in a ProgressMonitorInputStream StringBuffer contents = new StringBuffer(); InputStream in = new FileInputStream(fileAbsPath); ProgressMonitorInputStream pm = new ProgressMonitorInputStream(frame, "Reading the big file", in); int c = 0; while ((c = pm.read()) != -1) { contents.append((char) c); } pm.close(); String text = contents.toString(); editor.setText(text); } catch (Exception ex) { ex.printStackTrace(); } } }

Rispondi quotando