Jump to content
  • Advertisement
Sign in to follow this  
gamechampionx

Java monospaced fonts with FontMetrics.getHeight()

This topic is 4901 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!