Results 1 to 3 of 3
- 03-23-2008, 03:24 AM #1
Member
- Join Date
- Mar 2008
- Posts
- 2
- Rep Power
- 0
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
- 03-23-2008, 03:33 AM #2
Member
- Join Date
- Mar 2008
- Posts
- 2
- Rep Power
- 0
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.
- 03-25-2008, 05:49 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
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
-
How to write multiline String in a JLabel
By JavaBean in forum AWT / SwingReplies: 4Last Post: 12-14-2009, 05:09 AM -
Blurring pixels
By tim in forum New To JavaReplies: 0Last Post: 01-01-2008, 02:06 PM -
Determining Midi Length
By Usagi in forum New To JavaReplies: 0Last Post: 12-08-2007, 11:45 PM -
Help with method length
By toby in forum New To JavaReplies: 1Last Post: 07-25-2007, 08:29 PM -
How to know the exact word on which the mouse is, in a JTextArea
By JavaBean in forum AWT / SwingReplies: 1Last Post: 05-19-2007, 12:03 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks