Sign in to follow this  
gamechampionx

Java monospaced fonts with FontMetrics.getHeight()

Recommended Posts

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?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this