right align text with awt's drawString()?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: right align text with awt's drawString()?

  1. #1
    Join Date
    Mar 2000
    Location
    Vancouver, BC, Canada
    Posts
    277

    right align text with awt's drawString()?

    I'd like to right align the text against the edge of a line in an image. I've played with creating an algorythm based on font size, length of string... etc but it's not consistent.
    I was reading documentation based on a few other classes in Java for layout of text, but still can't quite grasp it.
    Anyone have a few lines of code to post to show me how?

  2. #2
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163
    Have you tried using FontMetrics.stringWidth(String str), or if anti-aliasing and fractional metrics hints are enabled, FontMetrics.getStringBounds(String str, Graphics context) ?

    There are only two kinds of programming languages: those people always ***** about and those nobody uses...
    B. Stroustrup
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  3. #3
    Join Date
    Mar 2000
    Location
    Vancouver, BC, Canada
    Posts
    277
    that was it...

    old saying my teacher Brian Pidcock used to say "it's easy once you 'get it'..." hahaha.

    thanks Dave. Don't know why i was making it so hard on myself. your response fixed it in about 10 seconds of typing.

  4. #4
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163
    If only all life's problems could be solved like that...

    Design and programming are human activities; forget that and all is lost...
    B. Stroustrup
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  5. #5
    Join Date
    Mar 2000
    Location
    Vancouver, BC, Canada
    Posts
    277
    I've thought the exact thing many times im my life....why no 'delete' button on the things you do....

    what normally happens in 'my life' (computing, not personal life...) is about 30 minutes of research, 2 hours of trying possible solutions, another 1 of research, a half day of trying to make earlier solutions work....switch to Java, find a sample on the net and go from there. If already working in java, eventually find the solution somewhere or from someone, and have it working if 5 minutes. it's a formula...hahhaa.

    with this one, I have no excuse...I must have been looking for fontImperialMeasurements() instead of fontMetrics() perhaps...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center