• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Fitting text into a field
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Fitting text into a field


  • Subject: Fitting text into a field
  • From: "Ernie" <email@hidden>
  • Date: Fri, 20 Sep 2002 16:14:51 -0400 (EDT)

Hi,

I have a text field (created with Interface Builder) in which I want to display a file's path. The data is in the format:

Macintosh HD:folder1:folder2:folder3:folder4:folder5:filename

If this is too wide to fit into the field, I want to keep shortening it in a loop until it fits, each time through the loop replacing a folder name with "...". So I would try:

Macintosh HD:folder1:folder2:folder3:folder4:folder5:filename
Macintosh HD:...:folder2:folder3:folder4:folder5:filename
Macintosh HD:...:...:folder3:folder4:folder5:filename
Macintosh HD:...:...:...:folder4:folder5:filename
Macintosh HD:...:...:...:...:folder5:filename
Macintosh HD:...:...:...:...:...:filename

until I found one that fits.

In order to do this, I need to be able to do 2 things:

1. Get the width of the text field
2. Get the width of a string

I can do #1, but I don't know how to go about doing #2. Can anyone tell me how I can get the width of some text as it would be displayed in a text field? Something like:

pixel-width-of "some-string" in text field "myfield" of window "Main"

Or, alternatively, a way of knowing if a given string can be displayed without truncation in a field. Something like:

will-fit "some-string" in text field "myfield" of window "Main"

Any help would be greatly appreciated!

E.D.

------------------------------------------------
Changed your e-mail? Keep your contacts! Use this free e-mail change of address service from Return Path. Register now!
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: Apple Script Dock Menu Items
  • Next by Date: Re: Ready made OSAX or script for a lazy programmer
  • Previous by thread: Re: Apple Script Dock Menu Items
  • Next by thread: Re: Ready made OSAX or script for a lazy programmer [HTML encoding]
  • Index(es):
    • Date
    • Thread