Solved

Font Size verus TextField Bounds

Posted on 1998-06-15
4
319 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ForLoop Example 3 40
replace a word with other 1 40
map related example 6 30
servlet example issue 6 29
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

919 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now