Code example for AttributedString

Methods: addAttribute, getIterator

0
		string = setFormatAndRemoveLabels(text);
 
		string = string.replaceAll("<<", "\u00AB");
		string = string.replaceAll(">>", "\u00BB");
 
		atrString = new AttributedString(string);
 
		atrString.addAttribute(TextAttribute.FAMILY, font.getFamily());
		atrString.addAttribute(TextAttribute.SIZE, fontSize);
		atrString.addAttribute(TextAttribute.WEIGHT, bold);
		atrString.addAttribute(TextAttribute.POSTURE, italic);
		atrString.addAttribute(TextAttribute.UNDERLINE, underline, 0, string.length());
 
		textLayout = new TextLayout(getAttributedCharacterIterator(), fontRenderContext);
	} 
	 
	public String getString() {
		return string;
	} 
	 
	public AttributedCharacterIterator getAttributedCharacterIterator() {
		return atrString.getIterator();
	} 
 
	private static String setFormatAndRemoveLabels(String s) {
		underline = -1; // UNDERLINE_OFF
		bold = TextAttribute.WEIGHT_REGULAR;