• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTextArea...

 
Tris Rabar
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,
Just a simple question...when using the JTextArea's method 'insert()', what kind of value does the position argument take? I mean, what position does it specify, for example if you have a textarea with x rows and y columns?
Thanks!
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you play around with it a bit, the answer soon reveals itself...
Starting with an empty JTextArea for each example:

inserts "hello" before the number 8,

inserts "hello" before the number 1, and

inserts "hello" before the number 0.
So, it looks like, the specified position is the position in the String contained in the JTextArea and counting starts at 0 at the beginning of the String - each character of the String being at a position in the String. And yes, the new line character '\n' counts as one character position.
Making sense?
Good Luck.
[ March 17, 2002: Message edited by: Dirk Schreckmann ]
 
Tris Rabar
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes it does! Thanks a lot!
 
Tris Rabar
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi again..
Does the row/column specifications in the JTextArea constructor allow you to insert values at identifed row/column positions? Or, is this just a way of specifying the area's size?
Thanks a lot!
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Tris Rabar:
Does the row/column specifications in the JTextArea constructor allow you to insert values at identifed row/column positions? Or, is this just a way of specifying the area's size?

After reading the JTextArea documentation, it becomes apparent what the available constructors do. Three constructors have parameters available for specifying rows and columns of the JTextArea - not for positioning text. This behavior soon reveals itself after making practice programs using them. If you were so inclined, you could use the new line character, '\n', and spaces in a string used with one of the available constructors to position your initial text. Note: The horizontal spacing is dependent on the font in use - one space character is (usually) not one column space.
Good Luck.
[ March 17, 2002: Message edited by: Dirk Schreckmann ]
 
Tris Rabar
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Dirk...
you guys are so helpful!
Very much appreciated.
 
Tris Rabar
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Dirk...
you guys are so helpful!
Very much appreciated.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic