File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes centralising characters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "centralising characters" Watch "centralising characters" New topic

centralising characters

John Coleman
Ranch Hand

Joined: Jul 24, 2001
Posts: 65
I want display individual characters centralised inside a box so that I can create a sort of grid with them equally spaced - this would be like a centered baseline monospaced characterset.

I can't see how with lower case letters once can discover how much to shift them to get them central, although this can be achieved somewhat with caps.

Is there any way to make my own font up perhaps, and bundle that with the application?


John Coleman, MSTA<br />Sun Certified Programmer for the Java� 2 Platform<br /><br />Eurobase banking solutions<br /><a href="" target="_blank" rel="nofollow"></a>
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
You can usually get pretty close using methods of the Font class.
Here's one way to do it.
Other options include the TextLayout and GlyphVector classes.
pete stein

Joined: Feb 23, 2007
Posts: 1561
Too cool! I twiddled it to show some lower-case characters too:

Thanks for the clever code.

I agree. Here's the link:
subject: centralising characters
It's not a secret anymore!