JTextArea insert() question

Discussion in 'Java' started by Jenny, Aug 18, 2004.

  1. Jenny

    Jenny Guest

    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
    Jenny, Aug 18, 2004
    #1
    1. Advertising

  2. Jenny

    Armel HERVE Guest

    In article <>,
    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
    Armel HERVE, Aug 18, 2004
    #2
    1. Advertising

  3. Jenny

    Paul Lutus Guest

    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
    Paul Lutus, Aug 18, 2004
    #3
  4. Jenny

    Battler Guest


    > > 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
    Battler, Aug 20, 2004
    #4
  5. Jenny

    Paul Lutus Guest

    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
    Paul Lutus, Aug 20, 2004
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ahmed Moustafa

    Tab key on JTextArea

    Ahmed Moustafa, Jun 28, 2003, in forum: Java
    Replies:
    1
    Views:
    2,804
    xarax
    Jun 28, 2003
  2. bad_knee
    Replies:
    0
    Views:
    516
    bad_knee
    Jul 13, 2003
  3. bad_knee
    Replies:
    2
    Views:
    551
    bad_knee
    Jul 14, 2003
  4. Ryan Tan via JavaKB.com

    JTextArea question

    Ryan Tan via JavaKB.com, Dec 8, 2004, in forum: Java
    Replies:
    10
    Views:
    7,766
    kolwas
    Jan 30, 2009
  5. :-o
    Replies:
    2
    Views:
    2,198
Loading...

Share This Page