Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / April 2005

Tip: Looking for answers? Try searching our database.

How to add rows of text to JTextArea

Thread view: 
brightoceanlight@hotmail.com - 24 Apr 2005 12:32 GMT
Is a way to add text to a JTextArea as rows?

For instance :

row1
row2
row3

?
Daniel - 24 Apr 2005 17:16 GMT
take a look at the insert method of the JTextArea
or if you want it at the very end the append method.
for your example it would be
JTextArea ta = JTextArea();
ta.appen("row1\n");
ta.appen("row2\n");
ta.appen("row3\n");

you may want to investigate the line-breaking further as I am not sure
this will work on all platforms.

but both the append and the insert methods seem to do the job you ask.

----
Daniel
http://www.daik.se

>Is a way to add text to a JTextArea as rows?
>
[quoted text clipped - 5 lines]
>
>?
Gil - 25 Apr 2005 08:57 GMT
> take a look at the insert method of the JTextArea
> or if you want it at the very end the append method.
[quoted text clipped - 3 lines]
> ta.appen("row2\n");
> ta.appen("row3\n");

It works! ta.append("row1\n");  Thanks very much for the help!

Best,

Gil
znôrt - 25 Apr 2005 13:05 GMT
(comp.lang.java.gui)

> It works! ta.append("row1\n");  Thanks very much for the help!

If you give some importance to portability (wich could be the case since
you're using Java), this is better:

ta.append("row1" + System.getProperty("line.separator")) ;
Thomas Weidenfeller - 25 Apr 2005 14:09 GMT
> If you give some importance to portability (wich could be the case since
> you're using Java), this is better:
>
> ta.append("row1" + System.getProperty("line.separator")) ;

No, not at all. line.separator identifies the operating system's line
separator, not the line separator used inside of Java. Java always uses
just '\n', except in I/O methods like like BufferedReader.readLine(),
which are supposed to to the necessary conversion.

If you append System.getProperty("line.separator") you in fact make your
application less portable, not more.

/Thomas

Signature

The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq

znôrt - 25 Apr 2005 19:08 GMT
> Java always uses
> just '\n', except in I/O methods like like
> BufferedReader.readLine(), which are supposed to to the
> necessary conversion.

Ok, I missed that, thanks. I thought '\n' was "generally acceptable" but not
the canonical thing. Good so, I guess every imaginable artifact you cuould
implent a VM for should have something you can map '\n' to.

> If you append System.getProperty("line.separator") you in
> fact make your application less portable, not more.

Yes, too bad!  8-o

znôrt


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.