Учитывая, что
JTextArea t = new JTextArea();
Document d = t.getDocument();
String word1 = "someWord";
String word2 = "otherWord"
int pos = t.getText().indexOf(word1,i);
В чем разница между ...
это
if(pos!= -1){
t.replaceRange(word2.toUpperCase(), pos, pos+ word1.length());
}
и это
if(pos!= -1){
d.remove(pos, word1.length());
d.insertString(pos, word2.toUpperCase(), null);
}