List of Topics:
Location Research Breakthrough Possible @S-Logix pro@slogix.in

Office Address

Social List

How to Use Tamil Font in Java?

Tamil Font in Java

Condition for Using Tamil Font in Java

  • Description: To use Tamil font in Java, the `Font` class from the `java.awt` package is used to set a specific font that supports Tamil characters. Ensure that a Tamil font, such as "Latha" or "Tamil MN", is available on the system. The font can be set by creating a `Font` object with the desired font name, style (e.g., plain, bold, etc.), and size. Once the `Font` object is created, it can be applied to UI components like `JLabel`, `JTextArea`, or `JButton` using the `setFont()` method. If the desired Tamil font is not available, a custom font file (e.g., `.ttf` or `.otf`) can be loaded using the `Font.createFont()` method and then set in the same manner. It is important to ensure that the Tamil characters are properly encoded (typically in Unicode) for correct display in the chosen font.
Sample Source Code
  • # TamilFont.java
    package JavaSamples2;

    import java.awt.Font;
    import javax.swing.JFrame;
    import javax.swing.JLabel;

    public class TamilFont {
    public static void main(String args[]){
    JFrame frame = new JFrame("Tamil Font Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(300, 200);

    JLabel label = new JLabel(" வணக்கம்");

    label.setFont(new Font("Latha", Font.PLAIN, 20));

    frame.add(label);
    frame.setVisible(true);
    }
    }
Screenshots
  • STEP 1: The JFrame window with the title "Tamil Font Example" is created.
  • The JFrame window with the title 'Tamil Font Example' is created.

Related Links