Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-23-2008, 04:24 AM
Member
 
Join Date: Mar 2008
Posts: 2
Clarkey is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 03-23-2008, 04:33 AM
Member
 
Join Date: Mar 2008
Posts: 2
Clarkey is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 03-25-2008, 06:49 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,532
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
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.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
(Close on July 27, 2008)
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Blurring pixels tim New To Java 0 01-01-2008 03:06 PM
Determining Midi Length Usagi New To Java 0 12-09-2007 12:45 AM
Help with method length toby New To Java 1 07-25-2007 09:29 PM
How to write multiline String in a JLabel JavaBean AWT / Swing 2 06-07-2007 06:19 PM
How to know the exact word on which the mouse is, in a JTextArea JavaBean AWT / Swing 1 05-19-2007 01:03 PM


All times are GMT +3. The time now is 01:01 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org