code: protected void addAttributes (AttributedString text)
      {
          // add any color attributes for specific segments
          if (_rawText != null) {
              Matcher m = COLOR_PATTERN.matcher(_rawText);
              int startSeg = 0, endSeg = 0;
              Color lastColor = null;
              while (m.find()) {
                  // color the segment just passed
                  endSeg += m.start();
                  if (lastColor != null) {
                      text.addAttribute(TextAttribute.FOREGROUND, lastColor, startSeg, endSeg);
                  }
  
                  // parse the tag: start or end a color
                  String group = m.group(1);
                  if ("x".equalsIgnoreCase(group)) {
                      lastColor = null;
                  } else {
                      lastColor = new Color(Integer.parseInt(group, 16));
                  }
  
                  // prepare for the next segment
                  startSeg = endSeg;
                  // Subtract the end of the segment from endSeg so that when we add the start of the
                  // next match we have actually added the length of the characters in between.
                  endSeg -= m.end();
              }
              // apply any final color to the tail segment
              if (lastColor != null) {
                  text.addAttribute(TextAttribute.FOREGROUND, lastColor, startSeg, _text.length());
              }
          }
      }
docs: Add any attributes to the text.