how to add sinhala to java GUI

Hi.. i think every programmer must aware about there own Unicode formats and how to add Unicode to their own program.I am going to say you how to enable java GUI with Sinhala Unicode values.

I am using Netbeans IDE and Java Development Kit 1.7 for develop Java programs.

Create a new form using Netbeans and add a Button from Swing containers. Then go to font item change it in to Iskoola pota. I used that Unicode font in my Program. See the image below

Then add a text to button as Unicode ( Sinahala ) format. You just copy the words from else where and paste it it text field. You will see something like \u0d86\u0dba values such as above my picture. Don’t worry in run time it will look like  as below picture.

Now you must be happy.

To view in Sinhala you must install the Sinhala Unicode for your computer. Other wise you will see some boxes in your button.

OK now you have done a Unicode based Java application using Java.

How to change Tooltips font in java / customize java Tooltips

Welcome again. Now i have different code for customize the  Tool tips in java programs. You can see i changed default tool tip font in to my own native language. It shows based on my Unicode language. I will show you how change this is.

String html =
            "<html><p><font color=\"#000\" " +
            "size=\"5\" face=\"Iskoola pota\">ආයුබෝවන් මෙම පනිවිඩය ඔබට සින්හලෙන් දිස්වන්නේ<br /> මෙම ජාවා වැඩසටහන සින්හල වැඩසටහනක්<br /> ලෙස සකසා ඇති නිසාය.." +


See i told you this is easy. OK i have set tool tips for my jButton1 using my native language. You want to call this inside your constructors. I think you got it know. If not see code

public class joption extends javax.swing.JFrame {

    /** Creates new form joption */
    public joption() {
        String html =
            "<html><p><font color=\"#000\" " +
            "size=\"5\" face=\"Iskoola pota\">ආයුබෝවන් මෙම පනිවිඩය ඔබට සින්හලෙන් දිස්වන්නේ<br /> මෙම ජාවා වැඩසටහන සින්හල වැඩසටහනක්<br /> ලෙස සකසා ඇති නිසාය.." +



I am using Netbeans as my IDE for develop java. If you have any problem please comment on this. Hope this was helpful to you friends.

how to set unicode(sinhala) font to JoptionPane in java / customize JoptionPane

Hi all now i am going to say you how to customize the JoptionPane in java. In here i  added Unicode type font to my message. Now we will see how to do it. Below you can see how you can customize your code for Unicode font..

String html =
            "<html><p><font color=\"#000\" " +
            "size=\"5\" face=\"Iskoola pota\">ආයුබෝවන් මෙම පනිවිඩය ඔබට සින්හලෙන් දිස්වන්නේ<br /> මෙම ජාවා වැඩසටහන සින්හල වැඩසටහනක්<br /> ලෙස සකසා ඇති නිසාය.." +

        JOptionPane.showMessageDialog(null, html,"තොරතුරු පනිවිඩය",JOptionPane.INFORMATION_MESSAGE);

How nice it has changed know.. OK friends we will see in next post..

How to insert Unicode values to MySQL using Java

Hello friends.. Today i have came up with something new for me.. and i think this will be useful for me.Specially for our Sri Lankan  friends who are willing to develop Sinhale Unicode based java programs.Here i used basic two concepts.

  • First one is Insert Unicode format values to MySQL database
  • Retrieve data and display it using a combo box.

I know if you can insert and retrieve data you can handle anything based on it. So lets starts the works. In this post i will tel you how to create a database in MySQL and create tables and fields to store data in Unicode format.

Another important thing you must know.I normally use my own ways when i am programming. I mean the way i am developing programs may be unique to me.Please consider about this when you are getting something from here.

Create a database in MySQL

  • I used phpMyAdmin to create my database and sometimes i used MySQL GUI tools for check my values.
  • MySQL GUI tools support to view Unicode values from a database
  • See my SQL backup file below and you can restore this backup file using phpMyAdmin.
-- Database: `unicode`
USE `unicode`;

-- --------------------------------------------------------

-- --------------------------------------------------------

-- Table structure for table `unicode`

  `name` varchar(100) NOT NULL,
  `job` varchar(50) NOT NULL,
  PRIMARY KEY (`id`)

Don’t worry at the end of the line you can download my database backup file. See i have created database in utf8_general_ci format and my table also in that format.

Now you have a database that you can store values in Unicode formats. If you cannot understand what i am saying see below screenshot. I got the

You can see some of values display as ??? and u0dc3 and my native language.

  • Up to 6 id i inserted values from manually using MySQL GUI tools.
  • In id 16 i inserted values from jTextBox and when i am insert it i got only ??? marks in my database.I tried several times using different methods but i couldn’t fix it.( Don’t worry i fixed it in this movement )

OK i am now going to give my Connection class. If you saw my previous posts i used my connection class in same way but now i added something extra to my connection class.

 * To change this template, choose Tools | Templates
 * and open the template in the editor.

package javaapplication1;

import java.sql.Connection;
import java.sql.DriverManager;
import javax.swing.JOptionPane;

 * @author Developer
public class connection {

    public Connection creatConnection () throws ClassNotFoundException
           Connection conn=null;

            Class.forName("com.mysql.jdbc.Driver").newInstance();//call jdbc driver
            String url = "jdbc:mysql://localhost/unicode?useUnicode=true&characterEncoding=UTF-8";//getting url
            conn = DriverManager.getConnection(url,"root","");//create connection

        catch (Exception e)
         // JOptionPane.showMessageDialog(null,"Error occured!.."+ e.getLocalizedMessage());
          JOptionPane.showMessageDialog(null, e.getMessage(), "Ooops",JOptionPane.ERROR_MESSAGE, null);//exeption hanling

        return conn;//return connection to all


OK. Now see clearly this code. I said i had some ??? values. The way i fixed it, i used this extra code to end of my string ( ?useUnicode=true&characterEncoding=UTF-8″; )

String url = “jdbc:mysql://localhost/unicode?useUnicode=true&characterEncoding=UTF-8”;

OK Now you created the connection class successfully. I will see you in next post How to insert data using java GUI.