Solved

Font Size verus TextField Bounds

Posted on 1998-06-15
4
320 Views
Last Modified: 2013-12-03
I always seem to have to edit, compile, run, edit, compile, run, etc...
when trying to get the TextField box to not cut off the text in it.

Is there any determinant way to set the bounds (height) of a TextField so that
the text that gets displayed in it doesn't get cut off.

I also need it to be platform and resolution independent.

I have tried three platforms:  Windows95, Linux (X), Solaris (CDE).
Windows handles it the best; whereis Solaris the worst.

0
Comment
Question by:mag062397
  • 2
  • 2
4 Comments
 
LVL 16

Expert Comment

by:imladris
ID: 1223211
Is the problem determining what height to set the TextField to, or getting the TextField to conform to the height you know it needs to be?

0
 

Author Comment

by:mag062397
ID: 1223212
Setting the TextField height so that it is large enough
to display the font, yet not too large.

That is, does there exist a constant, ?, such that
textField.setBounds(x, y, w, fontSize+?) is large enough
to display the font correctly and that ? is the smallest
constant that exists.

The answer probably depends on the font and/or fontsize; because
I tried setting the height to 25, font family to "TimesRoman" and
it displayed correctly for sizes 1-8 and 10 but not 9.  Strange!?

0
 
LVL 16

Accepted Solution

by:
imladris earned 150 total points
ID: 1223213
If you get a FontMetric for the font (in the Graphics class public FontMetrics getFontMetrics(Font f)) you can get the font height from it (public int getHeight()). There are also calls for getting the maximum ascent and descent (space above and below "regular" characters needed for this font.
This should allow for much more accuracy than a number based on font size.

0
 

Author Comment

by:mag062397
ID: 1223214
Yes, I'll do that -- Thanks!
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question