private void replaceRange(String newStr, int start, int end) { HTMLDocument doc = (HTMLDocument) getDocument(); try { doc.remove(start, (end - start)); insert(newStr, start); } catch (BadLocationException ble) { ble.printStackTrace(); } setDocument(doc); }