aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Font spacing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Font spacing" Watch "Font spacing" New topic
Author

Font spacing

Joe Ridener
Ranch Hand

Joined: Jul 16, 2012
Posts: 86
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

Joined: Oct 27, 2005
Posts: 19720
    
  20

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:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Joe Ridener
Ranch Hand

Joined: Jul 16, 2012
Posts: 86
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Font spacing