Graphics2D g2 = (Graphics2D)g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
RenderingHints.VALUE_FRACTIONALMETRICS_ON);
String s = "Camelopardalis";
Font font = new Font("Serif", Font.PLAIN, 32);
if (mTextLayout == null) {
FontRenderContext frc = g2.getFontRenderContext();
mTextLayout = new TextLayout(s, font, frc);
}
// Draw the highlight.
if (mFirstHit != null && mSecondHit != null) {
Shape base = mTextLayout.getLogicalHighlightShape(
mFirstHit.getInsertionIndex(), mSecondHit.getInsertionIndex());
AffineTransform at = AffineTransform.getTranslateInstance(mX, mY);
Shape highlight = at.createTransformedShape(base);
g2.setPaint(Color.green);
g2.fill(highlight);
}
g2.setPaint(Color.black);
mTextLayout.draw(g2, mX, mY);