int (int offset, @NotNull SimpleTextAttributes attributes) { synchronized (myFragments) { if (offset < 0 || offset > myEndOffset - myOffset) { throw new IllegalArgumentException(offset + " is not within [0, " + (myEndOffset - myOffset) + "]"); } ColoredFragment oldFragment = myFragments.get(myIndex); if (offset == myEndOffset - myOffset) { // replace oldFragment.attributes = attributes; } else if (offset > 0) { // split String text = getFragment(); ColoredFragment newFragment = new ColoredFragment(text.substring(offset), oldFragment.attributes, oldFragment.myComponent, oldFragment.myClipper); oldFragment.setText(text.substring(0, offset)); oldFragment.attributes = attributes; newFragment.tag = oldFragment; myFragments.add(myIndex + 1, newFragment); myIndex++; } myOffset += offset; return myOffset; } }