logical fonts in Java : Java Glossary

fonts logical fonts in Java
Jave defines set of logical fonts, aka desperation fonts, aka AWT (Advanced Windowing Toolkit) fonts, guaranteed to be available to every browser.

Logical fonts for Java Programs

If the font is installed, the sample text will show up in that font. If the font is not installed it will show up in a spindly vector font.

Dialog DialogInput Monospaced SansSerif Serif

Logical fonts for CSS (Cascading Style Sheets) Style Sheets

If the font is installed, the sample text will show up in that font. If the font is not installed it will show up in a spindly vector font.

cursive fantasy monospace sans-serif serif

The five Java logical fonts Dialog, DialogInput, Monospaced, SansSerif, Serif 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 (Hypertext Markup Language) or CSS. Note how they have slightly different spellings than the equivalent logical fonts in HTML/CSS: Java’s Monospaced vs CSS ’s monospace, SansSerif vs sans-serif and Serif vs serif.

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 into the OS (Operating System) 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 or Arial plus extra chars in Vista. comes with JRE (Java Runtime Environment)
DialogInput Courier New comes with Windows
Monospaced Courier New comes with Windows
SansSerif Lucida Sans or Arial plus extra chars in Vista. comes with JRE
Serif Times New Roman comes with Windows

In Vista, it would make more sense to map MonospacedConsolas and DialogSegoe UI. You could do that now by testing the platform and selecting specific rather than logical fonts when you are running under Vista.

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 Java version 1.4 or later 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.

available on the web at:

ClustrMaps is down

optional Replicator mirror
of mindprod.com
on local hard disk J:

Please the feedback from other visitors, or your own feedback about the site.
Contact Roedy.
Your face IP:[]
You are visitor number 11.