improving the look of Java Apps on Windows Vista
Use "FontFactory.build" instead of "new Font" and you will see a
remarkable improvement in your Java apps and Applications when run
under Windows Vista. It remaps the logical fonts to the best Vista
native fonts.
You can download this at http://mindprod.com/products1.html#COMMON11
It works in JDK 1.1+
package com.mindprod.common11;
import java.awt.Font;
/**
* Modifies Java's logical font mapping
*
* @author Roedy Green, Canadian Mind Products
* @version 1.0, 2008-08-20
* Created with IntelliJ IDEA.
*/
public class FontFactory
{
// -------------------------- PUBLIC STATIC METHODS
--------------------------
/**
* Creates a new <code>Font</code> from the specified name, style
and
* point size. Like new Font, but modifies the mapping of logical
fonts.
* <p/>
*
* @param fontFamilyName the font name. This can be a font face
name or a font
* family name, and may represent either a
logical font or a physical
* font
* The family names for logical fonts are:
Dialog, DialogInput,
* Monospaced, Serif, or SansSerif.
* @param style the style constant for the
<code>Font</code>
* The style argument is an integer bitmask
that may
* be PLAIN, or a bitwise union of BOLD
and/or ITALIC
* (for example, ITALIC or BOLD|ITALIC).
* @param size the point size of the <code>Font</code>
* @return corresponding Font, with logical fonts remapped for
Windows Vista to new native high res fonts.
*/
public static Font build( String fontFamilyName, final int style,
final int size )
{
String os = System.getProperty( "os.name", "unknown" );
/* we meddle with Vista logical font mapping. Potentially we
could meddle with others.
AIX
Digital Unix
FreeBSD
HP UX
Irix
Linux
Mac OS
Mac OS X
MPE/iX
Netware 4.11
OS/2
Solaris
Windows 2000
Windows 95
Windows 98
Windows NT
Windows Vista
Windows XP
*/
if ( os.equals( "Windows Vista" ) )
{
/* potentially meddle with various logical font mappings:
Dialog DialogInput Monospaced SansSerif Serif
and adjust sizes. */
if ( fontFamilyName.equals( "Dialog" ) )
{
fontFamilyName = "Segoe UI";
}
else if ( fontFamilyName.equals( "DialogInput" ) )
{
fontFamilyName = "Consolas";
}
else if ( fontFamilyName.equals( "Monospaced" ) )
{
fontFamilyName = "Consolas";
}
else if ( fontFamilyName.equals( "SanSerif" ) )
{
fontFamilyName = "Arial";
}
else if ( fontFamilyName.equals( "Serif" ) )
{
fontFamilyName = "Constantia";
}
}
// we could also cache fonts, or weakly cache them.
return new Font( fontFamilyName, style, size );
}
}
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com