How to monitor progress when reading a text file

Hi All!

I've created an application that read a text files and then displays it content onto

a JTextArea. The process is done well, how ever I need help to make my application

look better by putting progress bar(or else) to monitor the progress of reading the text file,

esp the big text file. How should I do it.

Below is a partial of the working code. My question is how and where to put the code

that monitor the progress. Any help please.

..

..

// Field for file path

JTextField tf_filePath;

String filePath ="";

..

..

JFileChooser fileChooser;

..

..

// open directory code goes here

fileChooser =new JFileChooser();

fileChooser.setFileSelectionMode(

JFileChooser.FILES_AND_DIRECTORIES);//DIRECTORIES_ONLY);

int returnVal = fileChooser.showOpenDialog(tf_filePath);

if(returnVal == JFileChooser.APPROVE_OPTION)

{

// do process when open file is true

File file = fileChooser.getSelectedFile();

tf_filePath.setText(file.getPath());

filePath = file.getPath();

String[] strData =new String[2];

strData = readDataFile(filePath);

ta_openFile.setText(strData[1]);

}

..

..

/*

This funtion is to read the text file and rearranged

the text line by line as in .txt file.

None existed file will return strData=[N,""]

Existed file will return strData=[Y, String of texts]

*/

public String[] readDataFile(String fileTM)

{

String record =null;

String[] strData =new String[2];

strData[0] ="N";// N - file not found, Y - found file

strData[1] ="";// to hold data

try{

FileReader fr =new FileReader(fileTM);

BufferedReader br =new BufferedReader(fr);

record =new String();

while ((record = br.readLine()) !=null)

{

strData[1] = strData[1] + record +"\n";

}

strData[0] ="Y";

}catch (IOException e)

{

// catch possible io errors from readLine()

System.out.println(" an IOException error!");

e.printStackTrace();

strData[0] ="N";

strData[1] ="";

}

return strData;

}

[3480 byte] By [awd1999a] at [2007-10-3 0:52:07]
# 1
[url http://java.sun.com/docs/books/tutorial/uiswing/components/progress.html]How to Use Progress Bars[/url]Check out the ProgressMonitiorInputStream.
camickra at 2007-7-14 17:47:13 > top of Java-index,Desktop,Core GUI APIs...