Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Font spacing

 
Joe Ridener
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have two difficult tasks at hand that involve the font spacing to be accurate. Is there any way to control the font spacing so that it will occupy a given cell before the next letter. Many people do not realize that when you use draw String as it is, it has the tendency to paint the letters unevenly side by side, one takes up 2 pixels the next may take up more and there is no space between them. Therefore, if you are trying to do something that involves character spacing it will not work as it is. It need additional control to provide a means of even spacing between letters. I want to get character and surrounding space to occupy one 10 pixel cell. Each and every letter. So that 10 letters take up 100 pixels or 70 at 7 pixel cells. Any ideas?
 
Rob Spoor
Sheriff
Pie
Posts: 20531
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you need each character to be equally wide you should use a monospaced font. You can create a java.awt.Font object quite easily:
 
Joe Ridener
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Rob,

I did actually come up with something that worked. I created a Font object like so
new Font("monospaced.plain",Font.Plain,12); It did actually work though it was less than perfect. I am doing a text pad from the ground up and JTextArea will not cut it although it might.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic