public void append(JTextPane j, Color c, String s) { // better implementation--uses // StyleContext StyleContext sc = StyleContext.getDefaultStyleContext(); AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY,StyleConstants.Foreground, c); int len = j.getDocument().getLength(); // same value as // getText().length(); j.setCaretPosition(len); // place caret at the end (with no selection) j.setCharacterAttributes(aset, false); j.replaceSelection(s); // there is no selection, so inserts at caret }