Now that you've made it clear that you want to draw only some characters of a string in a particular color (which is an important detail that should be mentioned in your question), you can, as others have mentioned, calculate the font metrics yourself for those characters.
But there can be more to drawing a single contiguous string than just FontMetrics, such as kerning and even connecting letters in certain scripts and fonts. Instead, I would use an AttributedCharacterIterator.
The easiest way to get an AttributedCharacterIterator is to create an AttributedString
:
AttributedString a = new AttributedString(text);
// We want first two characters drawn in red.
a.addAttribute(TextAttribute.FOREGROUND, Color.RED, 0, 2);
graphics.drawString(a.getIterator(), x, y);