Add Unicode to JLabel in Java

Description

The following code shows how to add Unicode to JLabel.

Example


/*  www .  java2 s  .  c  o m*/

import java.awt.GridLayout;

import javax.swing.JFrame;
import javax.swing.JLabel;

public class Main {
  public static void main(String args[]) {
    UnicodeJFrame unicodeJFrame = new UnicodeJFrame();
    unicodeJFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    unicodeJFrame.setSize(350, 250);
    unicodeJFrame.setVisible(true);
  } 
}

class UnicodeJFrame extends JFrame {
  public UnicodeJFrame() {
    super("Demonstrating Unicode");

    setLayout(new GridLayout(8, 1));

    JLabel englishJLabel = new JLabel("\u0057\u0065\u006C\u0063"
        + "\u006F\u006D\u0065\u0020\u0074\u006F\u0020Unicode\u0021");
    englishJLabel.setToolTipText("This is English");
    add(englishJLabel);

    JLabel chineseJLabel = new JLabel("\u6B22\u8FCE\u4F7F\u7528" + "\u0020\u0020Unicode\u0021");
    chineseJLabel.setToolTipText("This is Traditional Chinese");
    add(chineseJLabel);

    JLabel cyrillicJLabel = new JLabel("\u0414\u043E\u0431\u0440"
        + "\u043E\u0020\u043F\u043E\u0436\u0430\u043B\u043E\u0432"
        + "\u0430\u0422\u044A\u0020\u0432\u0020Unicode\u0021");
    cyrillicJLabel.setToolTipText("This is Russian");
    add(cyrillicJLabel);

    JLabel frenchJLabel = new JLabel("\u0042\u0069\u0065\u006E\u0076"
        + "\u0065\u006E\u0075\u0065\u0020\u0061\u0075\u0020Unicode\u0021");
    frenchJLabel.setToolTipText("This is French");
    add(frenchJLabel);

    JLabel germanJLabel = new JLabel("\u0057\u0069\u006C\u006B\u006F"
        + "\u006D\u006D\u0065\u006E\u0020\u007A\u0075\u0020Unicode\u0021");
    germanJLabel.setToolTipText("This is German");
    add(germanJLabel);

    JLabel japaneseJLabel = new JLabel("Unicode\u3078\u3087\u3045" + "\u3053\u305D\u0021");
    japaneseJLabel.setToolTipText("This is Japanese");
    add(japaneseJLabel);

    JLabel portugueseJLabel = new JLabel("\u0053\u00E9\u006A\u0061"
        + "\u0020\u0042\u0065\u006D\u0076\u0069\u006E\u0064\u006F\u0020" + "Unicode\u0021");
    portugueseJLabel.setToolTipText("This is Portuguese");
    add(portugueseJLabel);

    JLabel spanishJLabel = new JLabel("\u0042\u0069\u0065\u006E"
        + "\u0076\u0065\u006E\u0069\u0064\u0061\u0020\u0061\u0020" + "Unicode\u0021");
    spanishJLabel.setToolTipText("This is Spanish");
    add(spanishJLabel);
  } 
}

The code above generates the following result.

Add Unicode to JLabel in Java




















Home »
  Java Tutorial »
    Swing »




Action
Border
Color Chooser
Drag and Drop
Event
Font Chooser
JButton
JCheckBox
JComboBox
JDialog
JEditorPane
JFileChooser
JFormattedText
JFrame
JLabel
JList
JOptionPane
JPasswordField
JProgressBar
JRadioButton
JScrollBar
JScrollPane
JSeparator
JSlider
JSpinner
JSplitPane
JTabbedPane
JTable
JTextArea
JTextField
JTextPane
JToggleButton
JToolTip
JTree
Layout
Menu
Timer