In fin dei conti fa la stessa cosa.
Vai al codice sorgente di JTextArea
here, dove puoi scoprire che sta facendo la stessa cosa. Ho copiato il metodo qui anche il luogo dove si può trovare che si sta facendo
d.remove(pos, word1.length());
d.insertString(pos, word2.toUpperCase(), null);
in caso di chiamare:
t.replaceRange(word2.toUpperCase(), pos, pos+ word1.length());
metodo.
codice sorgente del metodo della classe è inferiore
public void replaceRange(String str, int start, int end) {
490 if (end < start) {
491 throw new IllegalArgumentException ("end before start");
492 }
493 Document doc = getDocument();
494 if (doc != null) {
495 try {
496 if (doc instanceof AbstractDocument) {
497 ((AbstractDocument)doc).replace(start, end - start, str,
498 null);
499 }
500 else {
501 doc.remove(start, end - start);
502 doc.insertString(start, str, null);
503 }
504 } catch (BadLocationException e) {
505 throw new IllegalArgumentException (e.getMessage());
506 }
507 }
508 }
fonte
2012-05-12 08:23:35
curioso: perché la taglia? non sei felice della tua risposta? – kleopatra