Meaningless Drivel is fun!*
The moose likes Swing / AWT / SWT and the fly likes How to get JTextArea to show input as it is being added? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to get JTextArea to show input as it is being added?" Watch "How to get JTextArea to show input as it is being added?" New topic
Author

How to get JTextArea to show input as it is being added?

myron schabe
Greenhorn

Joined: Aug 21, 2002
Posts: 19
Hi,
Want I want to do is have a JTextArea display strings as it is being added - sort of like showing progress. The code snippet I have below just (visually)dumps the contents into the text area when the loop is completed. What I want is the JTextArea to visually add the strings line by line as it is looping - so a user know that something is going on rather than a big long wait then a dump. Of course, setText() vs. append() doesn't work either as that doesn't concatentate. Validates or repaints don't seem to help. I am missing something. I can use another widget if it provides the desired affect.
JTextArea textArea = new JTextArea();
for(int i = 0; i <= 10000; i++)
{
textArea.append("blah blah blah blah...\n"); textArea.validate();
scrollPane.validate();
}

Many Thanks!
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

You'll have to add each line in a separate thread... something like this...



-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to get JTextArea to show input as it is being added?