Resetting TextArea

Discussion in 'Mac Programming' started by Alvinkiang, May 4, 2006.

  1. macrumors newbie

    Joined:
    Apr 24, 2006
    #1
    If i have Created this JTextArea and Pre-set it to editable(False)



    JTextArea text=new JTextArea("",60,50);
    JScrollPane pane= new JScrollPane(text);
    text.setText("Testing");
    panel.add(pane);
    text.setEditable(false);

    Anyway i can Reset the Text in it???
     
  2. macrumors 6502a

    Joined:
    Jun 17, 2003
    #2
    I assume you mean that you want to have your program change the contents of the JTextArea. You change the text using the following line:
    Code:
    text.setText("Some other text");
    
    The text.setEditable(false) line does not prevent the program from altering the contents of the text field. Instead, setEditable(boolean) controls whether the user of the program is able to edit the text in the textfield by clicking and typing into the field.

    Or, for a more interesting demonstration:

    Code:
    String scrollingTextString = "Some other text");
    for(int i=0; i<scrollingTextString.length(); i++) {
        // replace the text each time through loop removing first i characters
        text.setText(scrollingTextString.substring(i));
        // cause program to sleep for 250 milliseconds to slow down scroll
        Thread.sleep(250);
    }
    
     
  3. thread starter macrumors newbie

    Joined:
    Apr 24, 2006
    #3
    Er... i tried that method of .setText(); but i have a long list of error in the cmd when my button is press...

    By the way.. there are 1 lines which i nv paste which i thought might nt affect..

    JTextArea text=new JTextArea("",60,50);
    JScrollPane pane= new JScrollPane(text);
    text.setText("Testing");

    pane.setBounds(newPos[2*total1],newPos[2*total1+1],250,200); //<----- this line

    panel.add(pane);
    text.setEditable(false);


    that is used to read and set the actual location which i have set in a XML
     

Share This Page