Advertisement
Guest User

Untitled

a guest
Dec 14th, 2011
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. public void append(JTextPane j, Color c, String s) { // better implementation--uses
  2. // StyleContext
  3. StyleContext sc = StyleContext.getDefaultStyleContext();
  4. AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY,StyleConstants.Foreground, c);
  5.  
  6. int len = j.getDocument().getLength(); // same value as
  7. // getText().length();
  8. j.setCaretPosition(len); // place caret at the end (with no selection)
  9. j.setCharacterAttributes(aset, false);
  10. j.replaceSelection(s); // there is no selection, so inserts at caret
  11. }
  12.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement