Java monospaced fonts with FontMetrics.getHeight()

Started by
1 comment, last by earl3982 19 years, 2 months ago
Just a quick question with the following code:

import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Font;
import java.awt.FontMetrics;

public class Rogue extends Applet
{
	
	public void paint(Graphics g)
	{
		Font f = new Font("Monospaced", Font.BOLD, 20);
		g.setFont(f);
		FontMetrics fontInfo = g.getFontMetrics();
		for (int i=0; i<50; i++)
		{
			for (int j=1; j<=20; j++)
			{
				g.drawString("A", i * fontInfo.charWidth('A'), j * fontInfo.getHeight() - 1);
			}
		}
	}

}
This is extremely simple. It's ment to just write to an applet of preset size, with characters next to one another in a grid. The characters are horizontally touching as planned, but they have vertical gaps, probably because fontInfo.getHeight() gives a number that's "padded". Is there any way to have a monospaced fond without this vertical padding?
Check out Drunken Brawl at http://www.angelfire.com/games6/drunken_brawl!
Advertisement
Doesn't anybody here know anything about this topic?
Check out Drunken Brawl at http://www.angelfire.com/games6/drunken_brawl!
check out the TextLayout class

This topic is closed to new replies.

Advertisement