Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8241987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:01:10+00:00 2026-06-07T21:01:10+00:00

I am overriding the paintComponent() method of a JCOmponent and drawing text in a

  • 0

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:

Java app text

In the Ubuntu TextEditor, it looks like this:

enter image description here

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T21:01:11+00:00Added an answer on June 7, 2026 at 9:01 pm

    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:

    private Image getCompatibleImage(BufferedImage img) throws IOException {
            GraphicsConfiguration c = GraphicsEnvironment
                    .getLocalGraphicsEnvironment().getDefaultScreenDevice()
                    .getDefaultConfiguration();
    
            if (c.getColorModel().equals(img.getColorModel()))
                return img;
    
            BufferedImage compatible = c.createCompatibleImage(img.getWidth(),
                    img.getHeight());
            Graphics cg = compatible.getGraphics();
            cg.drawImage(img, 0, 0, null);
            cg.dispose();
    
            return compatible;
        }
    

    This will save per-pixel conversion on some monitors for increased performance.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In a sub-class of JComponent I am overriding paintComponent method to draw. The first
Overriding a method can be prevented by using the keyword final , likewise how
When overriding a method in Java is it possible to call the original one.
When overriding a non-virtual method in Java, use of the @Override annotation is recommended,
I'm currently overriding the default ModelMetadataProvider in the Global.asax file using this ModelMetadataProviders.Current =
Overriding Methods in java have the following features : 1> The Overrinding method should
I was studying method overriding in Java when ai came across the this keyword.
I would like to draw some shapes on a JPanel by overriding paintComponent .
I'm trying to print a JPanel with some painted graphics on it (overriding paintComponent).
when overriding the loadView method in UIViewController, should one call [super loadView] in the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.