PDA

View Full Version : Resetting TextArea




Alvinkiang
May 4, 2006, 08:36 PM
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???



mrichmon
May 4, 2006, 09:05 PM
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???

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:

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:


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);
}

Alvinkiang
May 4, 2006, 09:32 PM
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:

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:


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);
}


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