JTextArea insert() question

J

Jenny

Hi All,

The code below give me an err csused by a.insert("test \none",10).
If I use a.insert("test \none",0), it is OK. What can I do to use an
int >0 as position?

JTextArea a = new JTextArea(3,50);
a.insert("test \none",10);

Thanks.

The following is the info for insert.

public void insert(String str,
int pos)Inserts the specified text at the specified
position. Does nothing if the model is null or if the text is null or
empty.
This method is thread safe, although most Swing methods are not.
Please see Threads and Swing for more information.


Parameters:
str - the text to insert
pos - the position at which to insert >= 0
Throws:
IllegalArgumentException - if pos is an invalid position in the model
 
A

Armel HERVE

Hi All,

The code below give me an err csused by a.insert("test \none",10).
If I use a.insert("test \none",0), it is OK. What can I do to use an
int >0 as position?

JTextArea a = new JTextArea(3,50);
a.insert("test \none",10);
Your JTextArea is empty, so you can't insert a text at this pos...
If you want do this, maybe you can fill it before with spaces

Armel
 
P

Paul Lutus

Jenny said:
Hi All,

The code below give me an err csused by a.insert("test \none",10).
If I use a.insert("test \none",0), it is OK. What can I do to use an
int >0 as position?

First, find out what the current length of the text is, and then do not
exceed that length when you insert. The point is you cannot specify an
insertion point beyond the current length.
JTextArea a = new JTextArea(3,50);

This doesn't create any text content, it merely accepts the specified number
of rows and columns. It is still empty, and it will fail for an insert > 0.
 
B

Battler

This doesn't create any text content, it merely accepts the specified number
of rows and columns. It is still empty, and it will fail for an insert >
0.

Can the row and columns be treated as objects?

I thought maybe u can use it as a database.

Battler
 
P

Paul Lutus

Battler said:
0.

Can the row and columns be treated as objects?

I thought maybe u can use it as a database.

I think maybe "u" better tell us what you want to do. One is much better off
creating an array of the desired data types, instead of trying to use a
textarea as a database of rows and columns.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top