public static String addNewLines(String message)
  {
    BreakIterator boundary = 
      BreakIterator.getLineInstance();
    boundary.setText(message);
    int start = boundary.first();
    String result = "";
    String currLine = "";
    String temp = null;
    
    // loop till no more possible line breaks
    for (int end = boundary.next();
          end != BreakIterator.DONE;
          start = end, end = boundary.next()) 
    {
      // get string between start and end
      temp = message.substring(start,end);
      
      /* if adding that to the current line 
       * would make it too long then add current
       * to result followed by a newline and 
       * reset current 
       */
      if (temp.length() + currLine.length() > 100)
      {
        result = result + currLine + "\n";
        currLine = temp;
      }
      // else add the segment to the current line
      else 
        currLine = currLine + temp;
    }
 
    // if no line breaks use the original message
    if (result.length() == 0)
      result = message;
    // else add any leftover parts
    else
      result = result + currLine;
    
    return result;
  }