Figuring Out String Value for Font Constructor

K

kvnsmnsn

I've noticed that when I call "drawString()" without setting the font
first, the default font prints different widths for different charac-
ters. So I took a look at the "Font" class to try to figure out how
to call "setFont" to a font that has an equal width for each character
it prints. The API shows a contructor for "Font",
<Font ( String name, int style, int size)>, but you need to know what
string to put into <name>. Anybody have any idea how to figure out
the string value I need to put into this constructor to get it to use
a font that has an equal width for each character in the font? Any
information on this would be greatly appreciated.

---Kevin Simonson

"You'll never get to heaven, or even to LA,
if you don't believe there's a way."
from _Why Not_
 
D

Dotty

I've noticed that when I call "drawString()" without setting the font
first, the default font prints different widths for different charac-
ters. So I took a look at the "Font" class to try to figure out how
to call "setFont" to a font that has an equal width for each character
it prints. The API shows a contructor for "Font",
<Font ( String name, int style, int size)>, but you need to know what
string to put into <name>. Anybody have any idea how to figure out
the string value I need to put into this constructor to get it to use
a font that has an equal width for each character in the font? Any
information on this would be greatly appreciated.
I use this when I want a font where the columns line up.
"courier" or "Courier New" are also good.

static final Font treeFont = new Font("SansSerif", Font.PLAIN, 10);
 
T

Thomas Weidenfeller

I've noticed that when I call "drawString()" without setting the font
first, the default font prints different widths for different charac-
ters. So I took a look at the "Font" class to try to figure out how
to call "setFont" to a font that has an equal width for each character
it prints. The API shows a contructor for "Font",
<Font ( String name, int style, int size)>, but you need to know what
string to put into <name>. Anybody have any idea how to figure out
the string value I need to put into this constructor to get it to use
a font that has an equal width for each character in the font?

Yes, you read the API documentation of the Font class. Quote:
Logical fonts are the five font families defined by the Java platform which must be supported by any Java runtime environment: Serif, SansSerif, Monospaced, Dialog, and DialogInput.

/Thomas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,815
Latest member
treekmostly22

Latest Threads

Top