Hi all, first post here, and I most definitely am a greenhorn.
I have a program that reads in data from files, and then it analyzes that data, and then spits out an analysis of the data into an html page. This all works just fine. However, sometimes it takes the program a while to analyze the data file, as some of the data files that users read can be rather large. . And, if the data file IS a large file, I want status updates to be sent to the user, so they know the program is not hung.
So, the GUI of my program is a JPanel with a TextPanel that has a JTextArea, and that works fine too. That is, for the most part. Because, anytime I 'add' or 'append' text to the area it does work. However, and this is my problem, if the data file IS a large file, my status messages added to the JTextArea do not show up until AFTER the entire file has been analyzed, and by that point they are obviously useless.
TextPanel = new JPanel();
TextPanel.setLayout(new BorderLayout());
Text = new JTextArea("blah, blah",x,y);
Now, my program has a function where it determines the size of the file that the user specified for it to read. If the file is over a certain size, then it reads in chunks of the file at a time and then does analysis on each chunk, and after all chunks have been analyzed, it puts the file back together and all that works just fine, except for status updates.
It is in the part of the code that I want the status updates . . .
int numOFbuffers = filesize/buffersize;
if (numOFbuffers > 0)
{
moreData = true;
while (numOFbuffers >= 0)
{
Text.append("\nWorking...\n"); <-------------- write a status update
byte[] buffer = new byte[buffersize];
infile.read(buffer);
String fileData = new String(buffer);
analyzeData(fileData);
numOFbuffers--;
}
Alas, as I said, it will not show the updates until AFTER all of the buffers have been analyzed. So, I have tried repaint, requestfocus, etc and I cannot get this to work. How can I make this update while the program is executing?
Thanks in advance!