JTextArea...

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!

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 ]

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

Joined: Dec 10, 2001
Posts: 7023

posted Mar 17, 2002 20:08:00

0

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 ]