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) 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");
      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
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 %windir%\fonts\simsun.ttc file in your system directory tree.



 

Table of Contents

 About This Book

 JDK (Java Development Kit)

 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

 JFrame Thread Behavior with JDK 8 to 12

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

 JCheckBox - Swing Check Box Class

 JRadioButton - Swing Radio Button Class

 JTextField - Swing Text Field Class

 JComboBox - Swing Combo Box 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

 AWT (Abstract Windows Toolkit)

 Integration with Desktop System

 Outdated Tutorials

 References

 Full Version in PDF/EPUB