Java Swing Tutorials - Herong's Tutorial Examples
Dr. Herong Yang, Version 4.00

Displaying Chinese Characters in Frame Title

This section provides a tutorial example on the condition for the 'AWT blocker activation interrupted' error in JDK 1.6.0.

Problem: I want to display Chinese characters in the title of a frame window.

Solution: You can only do this if you are using JDK 1.4.2 and have a Unicode font installed to support Chinese characters. In my sample code listed below, I am using font SimSun, which was installed as part of Windows multi-language support.

/**
 * JFrameChinese.java
 * Copyright (c) 2004 by Dr. Herong Yang
 */
import java.awt.*;
import javax.swing.*;
public class JFrameChinese {
   public static void main(String[] a) {
      JFrame f = new JFrame();
      f.setFont(new Font("SimSun",Font.PLAIN, 12));
      f.setTitle("Hello world! - \u7535\u8111\u4F60\u597D\uFF01");
      f.setBounds(100,50,500,300);
      f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      f.setVisible(true);
   }
}

If you run this example, you will get:
Chinese Characters in Title Bar

Note 1: With JDK 1.4.1 or lower, the characters are displayed as "?". I don't any way to fix it. If you have any suggestions, please share them with me.

Note 2: To check if you have SimSun font installed or not, you can look for \winnt\fonts\simsun.ttc file in your system directory tree.

Sample programs listed in this section have been tested with JDK 1.4.2, 1.5.0. and 1.6.0

Last update: 2009.

Sections in This Chapter

Creating Frames with Sizes and Locations

Closing Frame and Terminating Application

Listing and Interrupting AWT Threads

"AWT blocker activation interrupted" Error

Displaying Chinese Characters in Frame Title

Drawing Graphics - Using paint() on Frame

Drawing Graphics - Using paint() on Component

Drawing Graphics - Using paint() on Content Pane

Drawing Chinese Characters on Frames

Dr. Herong Yang, updated in 2009
Displaying Chinese Characters in Frame Title