I'm writing a custom JComponent
and it will draw some text from a string.
Currently the text drawing code looks like this:
@Override
public void paintComponent(Graphics graphics) {
super.paintComponent(graphics);
Rectangle bounds = graphics.getClipBounds();
int maxAscent = graphics.getFontMetrics().getMaxAscent();
graphics.setColor(Color.BLACK);
graphics.drawString(text,bounds.x,bounds.y+maxAscent);
}
However, this draws aliased text. So I googled drawing antialiased text and found I could add these lines:
graphics2D.setRenderingHint(
RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
But then I thought... what else am I missing? And what if the user disables antialiased text and the current look and feel honors this but my code does not.
I want to draw the text as the current look and feel would draw the text. How can I do that?