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

  • SEARCH
  • Home
  • 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 7965043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:03:09+00:00 2026-06-04T06:03:09+00:00

Context The following code produces a nice looking Hello World graphics.drawString(Hello World, 30, 30);

  • 0

Context

The following code produces a “nice” looking "Hello World"

graphics.drawString("Hello World", 30, 30);

Now, if instead, I draw each character string, and manually advance by fontMetrics.getCharWidth(c) then I end up with a narrow/crowded looking "Hello World".

Questions

Why does this happen? What else do I need to add to, besides each character’s “advance”, to ensure that the characters are well spaced?

  • 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-04T06:03:10+00:00Added an answer on June 4, 2026 at 6:03 am

    which method in Graphics do you use to render char ?
    here is the code that I wrote and it runs perfectly and results of both rendering methods are exactly the same,
    would you please share that part of your code ?

    public class Test1 extends JPanel{
    
    public static void main(String[] args) {
    
        Test1 test = new Test1() ;
    
        JFrame frame = new JFrame() ;
        frame.add(test) ;
        frame.setSize(800 , 600) ;
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) ;
        frame.setVisible(true) ;
    
    }
    
    
    @Override
    public void paint(Graphics g) {     
        String text = "This is a text , Hello World!" ;
    
        g.drawString(text, 0, 100) ;        
        drawString(text, g, 0, 120) ;       
    }
    
    private void drawString (String s , Graphics g , int x , int y){
        for (int c1=0 ; c1 < s.length() ; c1++){
    
            char ch = s.charAt(c1); 
            g.drawString(ch+"", x, y) ;
            x+= g.getFontMetrics().charWidth(ch) ;
        }
    }
    

    }

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

Sidebar

Related Questions

In the following code below, I'm trying to translate, or more a graphics context
Imagine the following REBOL code: foo: context [bar: 3] I now have a context
I have a simple controller test, containing a.o. the following code: context POST :create
The following code doesn't work! 'this' in in the context when i access it
I have following code: //preparing DAO objects FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext(test-context.xml); surveyDao =
I have the following code in my context, and no explicit table-class mapping, yet
Imagine I have the following code (simplified regarding my real context of course): <div
I got the following code inside an NSTimer selector: [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:2.0];
I'm trying the following code.. LoadOperation<Tasks> PhasesLP = context. Load(context.GetTasksQuery(). Where(o=> ProjectList.Where(p=> p.ProjectID ==
All, I have the following code: $context = stream_context_create(array( 'http' => array( 'timeout' =>

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.