Java Swing How to - Add Unicode message to JTextArea








Question

We would like to know how to add Unicode message to JTextArea.

Answer

/*from w  w w .  ja va 2 s  .  c  om*/
import java.awt.Font;
import java.awt.GraphicsEnvironment;

import javax.swing.JFrame;
import javax.swing.JTextArea;

public class Main extends JFrame {

  String davidMessage = "\u05E9\u05DC\u05D5\u05DD \u05E2\u05D5\u05DC\u05DD";

  public Main() {
    GraphicsEnvironment.getLocalGraphicsEnvironment();
    JTextArea textArea = new JTextArea(davidMessage);
    textArea.setFont(new Font("LucidaSans", Font.PLAIN, 40));
    this.getContentPane().add(textArea);
    textArea.setVisible(true);
  }

  public static void main(String[] args) {
    JFrame frame = new Main();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    frame.pack();
    frame.setVisible(true);
  }
}