• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How can I show new text in JTextArea while program is executing?

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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!

 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://docs.oracle.com/javase/tutorial/uiswing/concurrency/index.html -- especially the section on SwingWorker
 
Dave Wilmsmeyer
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, so I was wondering if I would need to put this on its own thread. But, I was just checking to see if there was some other EZ way to do this, that I was missing.

Thank you!
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dave Wilmsmeyer wrote:EZ


Please UseRealWords: "easy", not "EZ".
 
Darryl Burke
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Spoor wrote:

Dave Wilmsmeyer wrote:EZ


Please UseRealWords: "easy", not "EZ".


Oh, is that what it means?
 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, that's what I make of it in this case. Pronunciation matches, and in this context it makes sense as well. In other cases / contexts EZ may mean something different.
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Spoor wrote: Pronunciation matches


Not if you're British it doesn't.
 
Darryl Burke
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Joanne Neal wrote:

Rob Spoor wrote: Pronunciation matches


Not if you're British it doesn't.


Not if you're Indian either.
reply
    Bookmark Topic Watch Topic
  • New Topic