SHARE
TWEET

Untitled

a guest Dec 14th, 2011 31 Never
  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.  
RAW Paste Data
Top