Solved

Font Size verus TextField Bounds

Posted on 1998-06-15
4
318 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Yes, I'll do that -- Thanks!
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
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.

743 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