Unicode with Label : JLabel « Swing « Java Tutorial






import java.awt.GridLayout;

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

public class Unicode {
  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);
  } 
}








14.3.JLabel
14.3.1.JLabel
14.3.2.Create JLabel component
14.3.3.Create a JLabel with an image icon
14.3.4.JLabel is for displaying text, images or both. It does not react to input events.
14.3.5.Horizontal Alignment: CENTER
14.3.6.Vertical Alignment: CENTER
14.3.7.Horizontal Alignment: LEFT
14.3.8.Vertical Alignment: TOP
14.3.9.Horizontal Alignment: RIGHT
14.3.10.Vertical Alignment: BOTTOM
14.3.11.The text is horizontally and vertically centered
14.3.12.The text is right-justified and vertically centered
14.3.13.The text is left-justified and top-aligned
14.3.14.The text is right-justified and top-aligned
14.3.15.The text is left-justified and bottom-aligned
14.3.16.The text is right-justified and bottom-aligned
14.3.17.Add Icon to JLabelAdd Icon to JLabel
14.3.18.Mix Icon and text in JLabelMix Icon and text in JLabel
14.3.19.Set Font and foreground color for a JLabelSet Font and foreground color for a JLabel
14.3.20.Load image from disk file and add it to a JLabelLoad image from disk file and add it to a JLabel
14.3.21.Using JLabel Mnemonics: Interconnect a specific JLabel and JTextField.Using JLabel Mnemonics: Interconnect a specific JLabel and JTextField.
14.3.22.Using a JLabel and pass in HTML for the textUsing a JLabel and pass in HTML for the text
14.3.23.Multiline label (HTML)
14.3.24.JLabel with more than one row
14.3.25.A simple Bean which extends JLabel
14.3.26.Add JLabel to JScrollPane
14.3.27.Disable a label
14.3.28.Unicode with Label
14.3.29.Customizing a JLabel Look and Feel
14.3.30.Associate JLabel component with a JTextField
14.3.31.Setting the Focus of a JTextField Component Using a JLabel Component
14.3.32.JLabel with lined border
14.3.33.A Label that uses inline HTML to format its text
14.3.34.A label with no indication it has been clicked
14.3.35.Adding Drag-and-Drop Support to a JLabel Component
14.3.36.Have a Label with underlined text
14.3.37.Multi Line Label
14.3.38.Vertical Label UI
14.3.39.Time panel shows the current time.
14.3.40.URL Label
14.3.41.Hyperlink Label
14.3.42.Gradient Label