Creating Labels with Chinese Characters

This section provides a tutorial example on how to create a label with Chinese characters with the javax.swing.JLabel class.

Problem: I want to create a label with Chinese characters.

Solution: Not very hard to do. See the following sample program:

 * Copyright (c) 2014,, All Rights Reserved.
import java.awt.*;
import javax.swing.*;
public class JLabelChinese {
   public static void main(String[] a) {
      JLabel l = new JLabel();
      l.setFont(new Font("SimSun",Font.PLAIN, 12));
      l.setText("Hello world! - \u7535\u8111\u4F60\u597D\uFF01");
      JFrame f = new JFrame();

If you run this example, you will get:
JLabel Test

Note: To run this program, you need to have SimSun font installed on your system. To verify this, search for C:\windows\fonts\simsun.ttc if you are using a Windows system.

Sample programs listed in this section have been tested with JDK 1.3.1 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

JLabel - Swing Label Class

 Creating Labels with javax.swing.JLabel Class

Creating Labels with Chinese Characters

 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