if ((getLength() + s.length()) > MAX_CHARACTERS) remove(0, s.length());
int len = s.length();   if (len >= MAX_CHARACTERS) { remove(0, MAX_CHARACTERS); super.insertString(0, s.substring(len - MAX_CHARACTERS), a); return; } int neededSpace = getLength() + len; if (neededSpace > MAX_CHARACTERS) remove(0, neededSpace - MAX_CHARACTERS);
  public void appendString(String s, AttributeSet a) {    try {      if ((getLength() + s.length()) > MAX_CHARACTERS)        remove(0, s.length());      super.insertString(getLength(), s, a);    } catch (BadLocationException ble) {      System.out.println("Bad location exception: " + ble);    }  }