Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Alvinkiang

macrumors newbie
Original poster
Apr 24, 2006
14
0
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

macrumors 6502a
Jun 17, 2003
873
3
Alvinkiang said:
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:
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);
}
 

Alvinkiang

macrumors newbie
Original poster
Apr 24, 2006
14
0
mrichmon said:
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);
}

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
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.