Given that
JTextArea t = new JTextArea();
Document d = t.getDocument();
String word1 = "someWord";
String word2 = "otherWord"
int pos = t.getText().indexOf(word1,i);
What is the difference between …
this
if(pos!= -1){
t.replaceRange(word2.toUpperCase(), pos, pos+ word1.length());
}
and this
if(pos!= -1){
d.remove(pos, word1.length());
d.insertString(pos, word2.toUpperCase(), null);
}
Ultimately it does the same thing.
Go to the source code of
JTextAreahere, where you can find that it is doing the same thing.I have copied the method here also where you can find that it is doing
in case of calling:
method.
Source code of the method of the class is below