Results 1 to 3 of 3
  1. #1
    Clarkey is offline Member
    Join Date
    Mar 2008
    Posts
    2
    Rep Power
    0

    Default Finding the exact length of a string in a JLabel (in pixels)

    Hi,

    I am making a program for my dads company, and am currently adding some effects to some of the things in it. One of them is calculating the exact length of a string so that I can alter the size of the JLabel to suit it (and so I can lengthen a JTextfield as it is typed in). I remember having this problem ages ago and I couldnt find a solution at all then.

    Does anyone have a solution to this?

    Thank you,

    Clarkey

  2. #2
    Clarkey is offline Member
    Join Date
    Mar 2008
    Posts
    2
    Rep Power
    0

    Default

    I just found the answer. Its getFontMetrics, then use the fontmetrics.stringWidth(text) to find out the width.

    This thread can be closed (or deleted) now.

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    It's nice to here that you have solve the problem by yourself.

    Actually no need to delete the thread pal. Your explanation may be helpful to others here in our community. :)

Similar Threads

  1. How to write multiline String in a JLabel
    By JavaBean in forum AWT / Swing
    Replies: 4
    Last Post: 12-14-2009, 05:09 AM
  2. Blurring pixels
    By tim in forum New To Java
    Replies: 0
    Last Post: 01-01-2008, 02:06 PM
  3. Determining Midi Length
    By Usagi in forum New To Java
    Replies: 0
    Last Post: 12-08-2007, 11:45 PM
  4. Help with method length
    By toby in forum New To Java
    Replies: 1
    Last Post: 07-25-2007, 08:29 PM
  5. Replies: 1
    Last Post: 05-19-2007, 12:03 PM

Posting Permissions

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