Home arrow static arrow Java Programming [Archive] - Setting Text in JTextArea..
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - Setting Text in JTextArea..
This topic has 5 replies on 1 page.

Posts:72
Registered: 4/30/04
Setting Text in JTextArea..  
Jul 28, 2004 4:36 AM



 
Hi
I want to fill a JTextArea one line at a time instead of setting the text as a whole.On the press of Button,I am calling actionPerformed method and i am setting the text in JTextArea.But its printing the whole contents to be displayed as a whole..I want my text to be displayed one line at a time after some time interval.I think we have to use Threading.But i don't know how to implement it..help me out..
Thanks for ur reply in advance.
 

Posts:24,036
Registered: 2/3/03
Re: Setting Text in JTextArea..  
Jul 28, 2004 5:41 AM (reply 1 of 5)



 
I want to fill a JTextArea one line at a time instead
of setting the text as a whole.On the press of
Button,I am calling actionPerformed method and i am
setting the text in JTextArea.But its printing the
whole contents to be displayed as a whole..I want my
text to be displayed one line at a time after some
time interval.

Common ways of introducing a delay in a Java program include Thread.sleep() and the use of the Timer class. Take a look at the following resources, which should give you a good idea of how to use these techniques:

[url=http://java.sun.com/docs/books/tutorial/essential/threads/]Java's Thread Tutorial[/url]
[url=http://java.sun.com/docs/books/tutorial/essential/threads/timer.html]Using the Timer and TimerTask Classes[/url]

Out of curiosity, what is it you're doing that you want users to wait on one line of information at a time?

Thanks for ur reply in advance.

[url=http://www.mnsu.edu/emuseum/archaeology/sites/middle_east/ur.html]UR information[/url]
 

Posts:72
Registered: 4/30/04
Re: Setting Text in JTextArea..  
Jul 28, 2004 5:56 AM (reply 2 of 5)



 
thanks for your reply..The thing is that i am getting certain set of values say qtyname,qtyid etc., from database..I am using jta.setText("") method to set the text of the textarea as a whole.But what i want to print connecting to database...for a while and after that qtyname should come and after a while qtyid...
i know to use Thread.sleep() but where to use it..whether i have to use it in action performed or during the call..
 

Posts:24,036
Registered: 2/3/03
Re: Setting Text in JTextArea..  
Jul 28, 2004 6:00 AM (reply 3 of 5)



 
Ah - look at JTextArea.append(). This will allow you to add information to the component, rather than overwriting it. You can call append() whenever you have the information you wish to display in the JTextArea.

It's an extremely important skill to learn to read the API and become familiar with the tools you will use to program Java. Java has an extensive set of [url=http://java.sun.com/reference/api/index.html]documentation[/url] that you can even [url=http://java.sun.com/docs/index.html]download[/url] for your convenience. These "javadocs" are indexed and categorized so you can quickly look up any class or method. Take the time to consult this resource whenever you have a question - you'll find they typically contain very detailed descriptions and possibly some code examples.

http://java.sun.com/reference/api/index.html
http://java.sun.com/j2se/1.4.2/docs/api/
 

Posts:72
Registered: 4/30/04
Re: Setting Text in JTextArea..  
Jul 28, 2004 6:16 AM (reply 4 of 5)



 
I think you have misunderstood the question or may be the way i asked is wrong.I don't want to overwrite my textarea..What i want is say i am having a textarea and i want to display like this

productid:abcd
name:xyz
qty:100
price:1000

The values of all these things are in database..On the click of fetch button i am getting these values printed on my textarea as a whole.But I don't want like this i want some time interval between printing of productid,name,qty,price(showing as if its taking some time to fetch from database)
 

Posts:24,036
Registered: 2/3/03
Re: Setting Text in JTextArea..  
Jul 28, 2004 6:23 AM (reply 5 of 5)



 
I think you have misunderstood the question or may be
the way i asked is wrong. I don't want to overwrite my textarea.

I think you have misunderstood the answer. JTextArea.append() does NOT overwrite the display. It appends a String to the JTextArea. Once again, read the API and the links I provided.

Don't get so caught up in the problem that you can't recognize the answer.
 
This topic has 5 replies on 1 page.