Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > JTextArea insert() question

Reply
Thread Tools

JTextArea insert() question

 
 
Jenny
Guest
Posts: n/a
 
      08-18-2004
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
 
Reply With Quote
 
 
 
 
Armel HERVE
Guest
Posts: n/a
 
      08-18-2004
In article <(E-Mail Removed) >,
http://www.velocityreviews.com/forums/(E-Mail Removed) says...
> 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
 
Reply With Quote
 
 
 
 
Paul Lutus
Guest
Posts: n/a
 
      08-18-2004
Jenny wrote:

> 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.

--
Paul Lutus
http://www.arachnoid.com

 
Reply With Quote
 
Battler
Guest
Posts: n/a
 
      08-20-2004

> > 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.

Can the row and columns be treated as objects?

I thought maybe u can use it as a database.

Battler



---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.737 / Virus Database: 491 - Release Date: 11/08/2004


 
Reply With Quote
 
Paul Lutus
Guest
Posts: n/a
 
      08-20-2004
Battler wrote:

>
>> > 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.
>
> 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.

--
Paul Lutus
http://www.arachnoid.com

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
JTextArea question Ryan Tan via JavaKB.com Java 10 01-30-2009 02:17 PM
JTextArea/text component question :-o Java 2 05-04-2005 10:54 PM
Re: JTextArea text is double-spaced? bad_knee Java 2 07-14-2003 05:23 PM
Re: JTextArea text is double-spaced? bad_knee Java 0 07-13-2003 10:24 PM
Tab key on JTextArea Ahmed Moustafa Java 1 06-28-2003 03:25 PM



Advertisments