for (int paragraphStart = 0, paragraphLimit;
paragraphStart < length;
paragraphStart = paragraphLimit) {
paragraphLimit = styledText.paragraphLimit(paragraphStart);
StyleModifier modifier = StyleModifier.createAddModifier(
TextAttribute.FOREGROUND,
COLORS[(i++)%COLORS.length]);
styledText.modifyCharacterStyles(paragraphStart,
paragraphLimit,
modifier);
}
StyleModifier modifier = StyleModifier.createAddModifier(
TextAttribute.LINE_FLUSH,
TextAttribute.FLUSH_CENTER);
styledText.modifyParagraphStyles(0, text.length(), modifier);