Why do Fonts suck in Java?

When it comes to fonts in Java, there seems to be a few holes. Two major ones that I just come across today:

  • No 'font chooser' dialog to let users graphically select a font.
  • No easy way to serialise a font to a properties/preferences text stream, despite the fact there is an easy way to read them in using Font.decode().

For the first issue, I simply made use of a component library we have (Jide), but it would be ideal if this component become a normal component in Swing. It isn't that difficult - I remember writing a font chooser back at university in an HCI paper using Java which was trivial (and actually focused more on the creation of custom UI components by overriding paint methods).

For the second issue, I seem to have some luck with the following method I just flicked together:

	public static String encodeFont(final Font f) {
		String style;
		if (f.isBold() && f.isItalic()) {
			style = "BOLDITALIC";
		} else if (f.isBold()) {
			style = "BOLD";
		} else if (f.isItalic()) {
			style = "ITALIC";
		} else {
			style = "PLAIN";
		}

		return f.getFontName() + "-" + style + "-" + f.getSize();
	}
}

Thoughts on “Why do Fonts suck in Java?”