Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Line by line output to JTextArea  RSS feed

 
Kansh Sahasrabuddhe
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey guys:

in my code, I am outputting all messages in JTextArea. The code runs fine but I get all messages at once when the program finishes. I want to be able to output the messages line by line as the code is processed.

currently i am using .append() to append messages to the JTextArea.

any idea how i might proceed? thanks
 
Fred Hamilton
Ranch Hand
Posts: 684
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kansh Sahasrabuddhe wrote:hey guys:

in my code, I am outputting all messages in JTextArea. The code runs fine but I get all messages at once when the program finishes. I want to be able to output the messages line by line as the code is processed.

currently i am using .append() to append messages to the JTextArea.

any idea how i might proceed? thanks


It might be an issue because you have sent the text to the output, but then your program is busy doing something else and hogging the CPU before the output can be displayed on the screen. I have had similar issues. The only way that I know of to deal with it is to use threads in one way or another.

Maybe someone else has a better idea on this.
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't run the code which updates the JTextArea on the Swing event thread. If you do, then you block the UI updates until the code is finished. (That's the behaviour you described, right?)

Swing concurrency tutorial: http://java.sun.com/docs/books/tutorial/uiswing/concurrency/
 
Fred Hamilton
Ranch Hand
Posts: 684
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Paul, you have nicely and succinctly formalized that which I have previously understood only intuitively. That provide me with a better framework to deal with the situation. regards.
 
Kansh Sahasrabuddhe
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:Don't run the code which updates the JTextArea on the Swing event thread. If you do, then you block the UI updates until the code is finished. (That's the behaviour you described, right?)

Swing concurrency tutorial: http://java.sun.com/docs/books/tutorial/uiswing/concurrency/


ya thats what i meant. thanks!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!