Displaying Chinese Characters in Frame Title

This section provides a tutorial example on how to display Chinese characters in the title bar of a frame window with a given Chinese font.

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 or higher 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) 2014, HerongYang.com, All Rights Reserved.
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");

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 to 1.8.0.

Last update: 2014.

Table of Contents

 About This Book

 Introduction of Java Swing Package

 Graphics Environment of the Local System

JFrame - Main Frame Class

 Creating Frames with Sizes and Locations

 Closing Frame and Terminating Application

 Listing and Interrupting AWT Threads

 "AWT blocker activation interrupted" Error

 "AWT blocker activation interrupted" Error in JDK 1.7

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

 JLabel - Swing Label Class

 JButton - Swing Button Class

 JRadioButton - Swing Radio Button Class

 JTextField - Swing Text Field Class

 Menu Bar, Menus, Menu Items and Listeners

 Creating Internal Frames inside the Main Frame

 Layout of Components in a Container

 LookAndFeel and UIManager

 Option Dialog Boxes

 JEditorPane - The Editor Pane Class

 SwingWorker - The Background Task Worker


 PDF Printing Version