Dec 02

We’ve all seen characters in our text being displayed with squares or questions marks instead of the expected character. Reason for this is the font being used does not include glyphs for the character(s) found in the string.

To display chinese (or any language) text requires a font that supports the characters used by the language. The Font classes canDisplayUpTo() method tests whether that Font is capable of displaying all the characters in a given string.

    	Font[] allFonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();
    	// The chinese text we will use to test
    	String sample = "\u4e00";    // unicode encoding
    	// Loop for each available font
    	for (int j = 0; j < allFonts.length; j++) {
    		// Test if the font can display the sample text
    	    if (allFonts[j].canDisplayUpTo(sample) == -1) { 

written by objects \\ tags: , , , ,