logical fonts : Java Glossary
home L words local find no local find frame, full screen Google search web for topic jump to footer translate with Babelfish 2008-03-28 by Roedy Green ©1996-2008 Canadian Mind Products
Go to : punctuation 0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z (all)
logical fonts
These logical fonts for Java Programs:
Dialog DialogInput Monospaced SansSerif Serif
These fonts are guaranteed available to every Java program. They will be automatically mapped onto the most suitable font available at a given platform. They generally will not work in HTML or CSS. Note how they have slightly different spellings than the equivalent in HTML/CSS. monospace vs Monospaced, sans-serif vs SansSerif and serif vs Serif. For more detail see the font essay.

Since every computer supports a different set of fonts, Sun decided to ensure at least these five fonts were supported everywhere: Serif, SansSerif, Monospaced, Dialog, and DialogInput. These are not actual fonts, but they map to some actual font either built-in to the OS or supplied by Sun in TrueType form. The key is these fonts you can count on being present everywhere.

If there were no logical fonts it would be impossible to write a program guaranteed to run everywhere since they are no physical fonts guaranteed to be installed everywhere. By mapping logical fonts to physical fonts, monospaced for example can be mapped onto the most popular monospaced font on a given platform, without Sun having to licence and provide the physical font for every conceivable platform.

Even though your computer may have hundreds of fonts installed, with AWT, you can only get at five of them, five chosen by Sun, (unless you use drawString). Sun chooses the physical fonts from ones it bundles and ones known to be installed with the OS, and then maps the five logical fonts onto five chosen physical ones. Sun chose physical fonts with support for a wide selection of Unicode characters to represent its logical fonts.

Note these logical font names that Java uses are slightly different from the names CSS uses for fonts of last resort: serif, sansserif and monospace.
Java Logical Fonts In Windows
Java Logical Font Corresponding Actual Font Notes
Dialog Lucida Sans comes with JRE
DialogInput Courier New comes with Windows
Monospaced Courier New comes with Windows
SansSerif Lucida Sans comes with JRE
Serif Times New Roman comes with Windows

These five Java logical fonts are the only fonts available for AWT peer components such as Label or TextArea. If you attempt to use other fonts, they will just display as Dialog. You must use Monospaced not Courier New. If you want use the other fonts, you will need to write a custom AWT component based on Canvas.
Happily, these Java logical fonts support many more characters than most fonts. They support Chinese, the various national currency characters and the mathematical and miscellaneous symbols.

In JDK 1.4+ and perhaps earlier you also have guaranteed Swing fonts Lucida Bright, Lucida Sans and Lucida Sans Typewriter which are not strictly speaking considered logical fonts, even though Sun makes them universally available by shipping them with the JRE.

Swing components can use the five Java logical fonts and any other scalable (i.e. OpenType, PostScript or TrueType) fonts installed on the system, e.g. Lucida Console or Tiresias PCFont Z.


CMP_homejump to top
CMP logo
feedback Please email your feedback for publication, errors, omissions, broken/redirected link reports
and suggestions to improve this page to Roedy Green : feedback email
made with CSS
HTML Checked!
ICRA ratings logo
mindprod.com IP:[65.110.21.43]
Your face IP:[38.103.63.18] The information on this page is for non-military use only.
You are visitor number 11. Military use includes use by defence contractors.
You can get a fresh copy of this page from: or possibly from your local J: drive (Java virtual drive/Mindprod website mirror)
http://mindprod.com/jgloss/logicalfonts.html J:\mindprod\jgloss\logicalfonts.html