I am overriding the paintComponent() method of a JCOmponent and drawing text in a window. I’m running on Ubuntu and using the font “Ubuntu Mono” (the default font for the Ubuntu text editor). When my java app displays the text, it looks wimpy and blurry. What am I doing wrong?
I’m drawing the text like this:
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
graphics.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
Font font = new Font("Ubuntu Mono", Font.PLAIN, 18);
fontMetrics = graphics.getFontMetrics(font);
graphics.setFont(font);
graphics.drawString(value, getX(), getY() + fontMetrics.getHeight());
In my java app, it looks like this:

In the Ubuntu TextEditor, it looks like this:

Edit: Would performance suffer if .png images were used instead of drawText()? This is a business application, not a game that requires smooth animation.
Edit: I changed the colors to match TextEditor’s colors and that actually helped a little on the quality, but the characters are still so much thinner… you almost can’t see a “.”. In gimp I can recreate the TextEditor look by creating text w/ the right font w/ antialiasing on.
Read the .png image and cache it to a BufferedImage. Performance would not suffer – actually using an intermediate image like this has better performance than drawing text in the first place.
Make sure you make it a compatible image like so:
This will save per-pixel conversion on some monitors for increased performance.